From 4abf666ba839b09c7aa55300037dd529848833e9 Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Mon, 12 Oct 2020 20:04:20 -0700 Subject: [PATCH 1/9] fixing action_type connection_type compatibility --- .../resource_sumologic_monitors_library_monitor.go | 10 +++++++--- sumologic/sumologic_monitors_library_monitor.go | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index 1bd7be9c..4bb58f4f 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -308,7 +308,9 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in if internalNotificationDict["connectionType"] != nil { internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string) } - internalNotification["action_type"] = internalNotificationDict["actionType"].(string) + if internalNotificationDict["actionType"] != nil { + internalNotification["action_type"] = internalNotificationDict["actionType"].(string) + } if internalNotification["action_type"].(string) == "EmailAction" || internalNotification["action_type"].(string) == "Email" || internalNotification["connection_type"].(string) == "EmailAction" || @@ -398,7 +400,8 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { notificationActionDict["connection_type"].(string) == "EmailAction" || notificationActionDict["connection_type"].(string) == "Email" { notificationAction := EmailNotification{} - notificationAction.ActionType = notificationActionDict["action_type"].(string) + // notificationAction.ActionType = notificationActionDict["action_type"].(string) + notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) notificationAction.Subject = notificationActionDict["subject"].(string) notificationAction.Recipients = notificationActionDict["recipients"].([]interface{}) notificationAction.MessageBody = notificationActionDict["message_body"].(string) @@ -406,7 +409,8 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n.Notification = notificationAction } else { notificationAction := WebhookNotificiation{} - notificationAction.ActionType = notificationActionDict["action_type"].(string) + // notificationAction.ActionType = notificationActionDict["action_type"].(string) + notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) notificationAction.ConnectionID = notificationActionDict["connection_id"].(string) notificationAction.PayloadOverride = notificationActionDict["payload_override"].(string) n.Notification = notificationAction diff --git a/sumologic/sumologic_monitors_library_monitor.go b/sumologic/sumologic_monitors_library_monitor.go index 16919d96..7a7cf40d 100644 --- a/sumologic/sumologic_monitors_library_monitor.go +++ b/sumologic/sumologic_monitors_library_monitor.go @@ -141,6 +141,12 @@ type MonitorNotification struct { RunForTriggerTypes []interface{} `json:"runForTriggerTypes"` } +type Notification struct { + ActionType string `json:"actionType,omitempty"` + ConnectionType string `json:"connectionType,omitempty"` + ConnectionID string `json:"connectionId"` +} + type EmailNotification struct { ActionType string `json:"actionType,omitempty"` ConnectionType string `json:"connectionType,omitempty"` From 4e854ba39616b01533362dce225c2554e967d23c Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Wed, 14 Oct 2020 14:27:27 -0700 Subject: [PATCH 2/9] more fixes --- sumologic/resource_sumologic_monitors_library_monitor.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index 4bb58f4f..6848aaac 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -305,6 +305,8 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in schemaInternalNotification := make([]interface{}, 1) internalNotification := make(map[string]interface{}) internalNotificationDict := n.Notification.(map[string]interface{}) + log.Printf("internalNotificationDict %v", internalNotificationDict) + log.Printf("monitor.Notification %v", n.Notification) if internalNotificationDict["connectionType"] != nil { internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string) } @@ -395,12 +397,13 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n := MonitorNotification{} rawNotificationAction := notificationDict["notification"].([]interface{}) notificationActionDict := rawNotificationAction[0].(map[string]interface{}) + log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict) if notificationActionDict["action_type"].(string) == "EmailAction" || notificationActionDict["action_type"].(string) == "Email" || notificationActionDict["connection_type"].(string) == "EmailAction" || notificationActionDict["connection_type"].(string) == "Email" { notificationAction := EmailNotification{} - // notificationAction.ActionType = notificationActionDict["action_type"].(string) + notificationAction.ActionType = notificationActionDict["action_type"].(string) notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) notificationAction.Subject = notificationActionDict["subject"].(string) notificationAction.Recipients = notificationActionDict["recipients"].([]interface{}) @@ -409,7 +412,7 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n.Notification = notificationAction } else { notificationAction := WebhookNotificiation{} - // notificationAction.ActionType = notificationActionDict["action_type"].(string) + notificationAction.ActionType = notificationActionDict["action_type"].(string) notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) notificationAction.ConnectionID = notificationActionDict["connection_id"].(string) notificationAction.PayloadOverride = notificationActionDict["payload_override"].(string) From bfbc40646668bc4c9bc96868f7117fcd7c3857fe Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Wed, 14 Oct 2020 15:14:12 -0700 Subject: [PATCH 3/9] transform old action type to connection type transparently --- ...urce_sumologic_monitors_library_monitor.go | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index 6848aaac..36308da4 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -305,23 +305,31 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in schemaInternalNotification := make([]interface{}, 1) internalNotification := make(map[string]interface{}) internalNotificationDict := n.Notification.(map[string]interface{}) - log.Printf("internalNotificationDict %v", internalNotificationDict) - log.Printf("monitor.Notification %v", n.Notification) + log.Printf("internalNotificationDict before: %v", internalNotificationDict) + // log.Printf("monitor.Notification %v", n.Notification) if internalNotificationDict["connectionType"] != nil { internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string) + } else { + // for backwards compatibility + internalNotification["connection_type"] = internalNotificationDict["actionType"].(string) + // convert from old action_type name to new connection_type name if applicable + if internalNotification["connection_type"].(string) == "EmailAction" { + internalNotification["connection_type"] = "Email" + } + if internalNotification["connection_type"].(string) == "NamedConnectionAction" { + internalNotification["connection_type"] = "Webhook" + } } - if internalNotificationDict["actionType"] != nil { - internalNotification["action_type"] = internalNotificationDict["actionType"].(string) - } - if internalNotification["action_type"].(string) == "EmailAction" || - internalNotification["action_type"].(string) == "Email" || - internalNotification["connection_type"].(string) == "EmailAction" || - internalNotification["connection_type"].(string) == "Email" { + log.Printf("internalNotification after fixing: %v", internalNotification) + if internalNotification["connection_type"].(string) == "Email" { + // for backwards compatibility + internalNotification["action_type"] = "EmailAction" internalNotification["subject"] = internalNotificationDict["subject"].(string) internalNotification["recipients"] = internalNotificationDict["recipients"].([]interface{}) internalNotification["message_body"] = internalNotificationDict["messageBody"].(string) internalNotification["time_zone"] = internalNotificationDict["timeZone"].(string) } else { + internalNotification["action_type"] = "NamedConnectionAction" internalNotification["connection_id"] = internalNotificationDict["connectionId"].(string) if internalNotificationDict["payloadOverride"] != nil { internalNotification["payload_override"] = internalNotificationDict["payloadOverride"].(string) @@ -398,10 +406,7 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { rawNotificationAction := notificationDict["notification"].([]interface{}) notificationActionDict := rawNotificationAction[0].(map[string]interface{}) log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict) - if notificationActionDict["action_type"].(string) == "EmailAction" || - notificationActionDict["action_type"].(string) == "Email" || - notificationActionDict["connection_type"].(string) == "EmailAction" || - notificationActionDict["connection_type"].(string) == "Email" { + if notificationActionDict["connection_type"].(string) == "Email" { notificationAction := EmailNotification{} notificationAction.ActionType = notificationActionDict["action_type"].(string) notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) From 17f65b7105b25c2f55dfc53672db73ec70cebcc9 Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Wed, 14 Oct 2020 15:27:28 -0700 Subject: [PATCH 4/9] fixing create to be in parity with read --- ...urce_sumologic_monitors_library_monitor.go | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index 36308da4..e12d7c76 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -305,7 +305,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in schemaInternalNotification := make([]interface{}, 1) internalNotification := make(map[string]interface{}) internalNotificationDict := n.Notification.(map[string]interface{}) - log.Printf("internalNotificationDict before: %v", internalNotificationDict) + log.Printf("[ROHIT DEBUG] internalNotificationDict before: %v", internalNotificationDict) // log.Printf("monitor.Notification %v", n.Notification) if internalNotificationDict["connectionType"] != nil { internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string) @@ -320,7 +320,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in internalNotification["connection_type"] = "Webhook" } } - log.Printf("internalNotification after fixing: %v", internalNotification) + log.Printf("[ROHIT DEBUG] internalNotification after fixing: %v", internalNotification) if internalNotification["connection_type"].(string) == "Email" { // for backwards compatibility internalNotification["action_type"] = "EmailAction" @@ -405,11 +405,27 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n := MonitorNotification{} rawNotificationAction := notificationDict["notification"].([]interface{}) notificationActionDict := rawNotificationAction[0].(map[string]interface{}) + var connectionType string + var actionType string log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict) - if notificationActionDict["connection_type"].(string) == "Email" { + if notificationActionDict["connection_type"] != nil { + connectionType = notificationActionDict["connection_type"].(string) + } else { + // for backwards compatibility + actionType = notificationActionDict["action_type"].(string) + connectionType = actionType + // convert from old action_type name to new connection_type name if applicable + if connectionType == "EmailAction" { + connectionType = "Email" + } + if connectionType == "NamedConnectionAction" { + connectionType = "Webhook" + } + } + if connectionType == "Email" { notificationAction := EmailNotification{} - notificationAction.ActionType = notificationActionDict["action_type"].(string) - notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) + notificationAction.ActionType = actionType + notificationAction.ConnectionType = connectionType notificationAction.Subject = notificationActionDict["subject"].(string) notificationAction.Recipients = notificationActionDict["recipients"].([]interface{}) notificationAction.MessageBody = notificationActionDict["message_body"].(string) @@ -417,13 +433,14 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n.Notification = notificationAction } else { notificationAction := WebhookNotificiation{} - notificationAction.ActionType = notificationActionDict["action_type"].(string) - notificationAction.ConnectionType = notificationActionDict["connection_type"].(string) + notificationAction.ActionType = actionType + notificationAction.ConnectionType = connectionType notificationAction.ConnectionID = notificationActionDict["connection_id"].(string) notificationAction.PayloadOverride = notificationActionDict["payload_override"].(string) n.Notification = notificationAction } n.RunForTriggerTypes = notificationDict["run_for_trigger_types"].([]interface{}) + log.Printf("[ROHIT DEBUG] Notification object: %v", n.Notification) notifications[i] = n } return notifications From 2e18fc5d1285ab16c13e218641d3cf697bb0aaf0 Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Wed, 14 Oct 2020 15:44:55 -0700 Subject: [PATCH 5/9] fixing action_type without connection_type --- ...urce_sumologic_monitors_library_monitor.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index e12d7c76..df095a2b 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -135,10 +135,12 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource { "action_type": { Type: schema.TypeString, Optional: true, + Computed: true, }, "connection_type": { Type: schema.TypeString, Optional: true, + Computed: true, }, "subject": { Type: schema.TypeString, @@ -183,7 +185,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource { "description": { Type: schema.TypeString, - Required: true, + Optional: true, }, "created_at": { @@ -405,14 +407,19 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n := MonitorNotification{} rawNotificationAction := notificationDict["notification"].([]interface{}) notificationActionDict := rawNotificationAction[0].(map[string]interface{}) - var connectionType string - var actionType string + connectionType := "" + actionType := "" log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict) - if notificationActionDict["connection_type"] != nil { + if notificationActionDict["connection_type"] != nil && + notificationActionDict["connection_type"] != "" { connectionType = notificationActionDict["connection_type"].(string) + actionType = connectionType + log.Printf("[ROHIT DEBUG] actionType in if: %v", actionType) + log.Printf("[ROHIT DEBUG] connectionType in if: %v", connectionType) } else { // for backwards compatibility actionType = notificationActionDict["action_type"].(string) + log.Printf("[ROHIT DEBUG] actionType in else: %v", actionType) connectionType = actionType // convert from old action_type name to new connection_type name if applicable if connectionType == "EmailAction" { @@ -421,9 +428,13 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { if connectionType == "NamedConnectionAction" { connectionType = "Webhook" } + log.Printf("[ROHIT DEBUG] connectionType in else: %v", connectionType) } + log.Printf("[ROHIT DEBUG] actionType: %v", actionType) + log.Printf("[ROHIT DEBUG] connectionType: %v", connectionType) if connectionType == "Email" { notificationAction := EmailNotification{} + actionType = "EmailAction" notificationAction.ActionType = actionType notificationAction.ConnectionType = connectionType notificationAction.Subject = notificationActionDict["subject"].(string) @@ -433,6 +444,7 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n.Notification = notificationAction } else { notificationAction := WebhookNotificiation{} + actionType = "NamedConnectionAction" notificationAction.ActionType = actionType notificationAction.ConnectionType = connectionType notificationAction.ConnectionID = notificationActionDict["connection_id"].(string) From 02a5c9d3384ccb4f670ac957da5db1e53743b899 Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Wed, 14 Oct 2020 18:12:08 -0700 Subject: [PATCH 6/9] updated docs with webhook examples and updated field names --- website/docs/r/monitor.html.markdown | 129 ++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 13 deletions(-) diff --git a/website/docs/r/monitor.html.markdown b/website/docs/r/monitor.html.markdown index 595af54f..f2ee461c 100644 --- a/website/docs/r/monitor.html.markdown +++ b/website/docs/r/monitor.html.markdown @@ -32,15 +32,33 @@ resource "sumologic_monitor" "tf_logs_monitor_1" { trigger_type = "Critical" detection_method = "StaticCondition" } + triggers { + threshold_type = "LessThanOrEqual" + threshold = 40.0 + time_range = "15m" + occurrence_type = "ResultCount" + trigger_source = "AllResults" + trigger_type = "ResolvedCritical" + detection_method = "StaticCondition" + } notifications { notification { - action_type = "EmailAction" - recipients = ["abc@example.com"] - subject = "Triggered: tf logs monitor" - time_zone = "PST" - message_body = "testing123" + connection_type = "Email" + recipients = [ + "abc@example.com", + ] + subject = "Monitor Alert: {{TriggerType}} on {{Name}}" + time_zone = "PST" + message_body = "Triggered {{TriggerType}} Alert on {{Name}}: {{QueryURL}}" } - run_for_trigger_types = ["Critical"] + run_for_trigger_types = ["Critical", "ResolvedCritical"] + } + notifications { + notification { + connection_type = "Webhook" + connection_id = "0000000000ABC123" + } + run_for_trigger_types = ["Critical", "ResolvedCritical"] } } ``` @@ -53,7 +71,6 @@ resource "sumologic_monitor" "tf_metrics_monitor_1" { description = "tf metrics monitor" type = "MonitorsLibraryMonitor" is_disabled = false - parent_id = "0000000000000001" content_type = "Monitor" monitor_type = "Metrics" queries { @@ -80,17 +97,103 @@ resource "sumologic_monitor" "tf_metrics_monitor_1" { } notifications { notification { - action_type = "EmailAction" - recipients = ["abc@example.com"] - subject = "Triggered: tf metrics monitor" - time_zone = "PST" - message_body = "testing123" + connection_type = "Email" + recipients = ["abc@example.com"] + subject = "Triggered {{TriggerType}} Alert on Monitor {{Name}}" + time_zone = "PST" + message_body = "Triggered {{TriggerType}} Alert on {{Name}}: {{QueryURL}}" } run_for_trigger_types = ["Critical","ResolvedCritical"] } } ``` +## Example Logs Monitor with Webhook Connection and Folder + +```hcl +resource "sumologic_monitor_folder" "tf_monitor_folder_1" { + name = "Terraform Managed Folder 1" + description = "A folder for Monitors" +} + +resource "sumologic_connection" "example_pagerduty_connection" { + name = "example_pagerduty_connection" + description = "PagerDuty connection for notifications from Monitors" + type = "WebhookConnection" + webhook_type = "PagerDuty" + url = "https://events.pagerduty.com/" + default_payload = < Date: Wed, 14 Oct 2020 18:17:33 -0700 Subject: [PATCH 7/9] cleaned up debug log lines --- .../resource_sumologic_monitors_library_monitor.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index df095a2b..687a3153 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -307,7 +307,6 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in schemaInternalNotification := make([]interface{}, 1) internalNotification := make(map[string]interface{}) internalNotificationDict := n.Notification.(map[string]interface{}) - log.Printf("[ROHIT DEBUG] internalNotificationDict before: %v", internalNotificationDict) // log.Printf("monitor.Notification %v", n.Notification) if internalNotificationDict["connectionType"] != nil { internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string) @@ -322,7 +321,6 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in internalNotification["connection_type"] = "Webhook" } } - log.Printf("[ROHIT DEBUG] internalNotification after fixing: %v", internalNotification) if internalNotification["connection_type"].(string) == "Email" { // for backwards compatibility internalNotification["action_type"] = "EmailAction" @@ -409,17 +407,13 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { notificationActionDict := rawNotificationAction[0].(map[string]interface{}) connectionType := "" actionType := "" - log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict) if notificationActionDict["connection_type"] != nil && notificationActionDict["connection_type"] != "" { connectionType = notificationActionDict["connection_type"].(string) actionType = connectionType - log.Printf("[ROHIT DEBUG] actionType in if: %v", actionType) - log.Printf("[ROHIT DEBUG] connectionType in if: %v", connectionType) } else { // for backwards compatibility actionType = notificationActionDict["action_type"].(string) - log.Printf("[ROHIT DEBUG] actionType in else: %v", actionType) connectionType = actionType // convert from old action_type name to new connection_type name if applicable if connectionType == "EmailAction" { @@ -428,10 +422,7 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { if connectionType == "NamedConnectionAction" { connectionType = "Webhook" } - log.Printf("[ROHIT DEBUG] connectionType in else: %v", connectionType) } - log.Printf("[ROHIT DEBUG] actionType: %v", actionType) - log.Printf("[ROHIT DEBUG] connectionType: %v", connectionType) if connectionType == "Email" { notificationAction := EmailNotification{} actionType = "EmailAction" @@ -452,7 +443,6 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification { n.Notification = notificationAction } n.RunForTriggerTypes = notificationDict["run_for_trigger_types"].([]interface{}) - log.Printf("[ROHIT DEBUG] Notification object: %v", n.Notification) notifications[i] = n } return notifications From f084fdb9e561a0a56916b3f29b9da3ae207e3860 Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Thu, 15 Oct 2020 15:51:03 -0700 Subject: [PATCH 8/9] added deprecation notice and updated tests with connection_type instead of action_type --- ...urce_sumologic_monitors_library_monitor.go | 7 +-- ...sumologic_monitors_library_monitor_test.go | 48 +++++++++---------- .../sumologic_monitors_library_monitor.go | 6 --- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index 687a3153..1c272287 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -133,9 +133,10 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "action_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + Deprecated: "The field `action_type` is deprecated and will be removed in a future release of the provider - please use `connection_type` instead.", }, "connection_type": { Type: schema.TypeString, diff --git a/sumologic/resource_sumologic_monitors_library_monitor_test.go b/sumologic/resource_sumologic_monitors_library_monitor_test.go index 50fbcbf4..a16b2cd6 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor_test.go +++ b/sumologic/resource_sumologic_monitors_library_monitor_test.go @@ -74,17 +74,17 @@ func TestAccMonitorsLibraryMonitor_create(t *testing.T) { for i, v := range recipients { testRecipients[i] = v } - triggerTypes := []string{"Critical"} + triggerTypes := []string{"Critical", "ResolvedCritical"} testTriggerTypes := make([]interface{}, len(triggerTypes)) for i, v := range triggerTypes { testTriggerTypes[i] = v } testNotificationAction := EmailNotification{ - ActionType: "EmailAction", - Recipients: testRecipients, - Subject: "test tf monitor", - TimeZone: "PST", - MessageBody: "test", + ConnectionType: "Email", + Recipients: testRecipients, + Subject: "test tf monitor", + TimeZone: "PST", + MessageBody: "test", } testNotifications := []MonitorNotification{ { @@ -111,7 +111,7 @@ func TestAccMonitorsLibraryMonitor_create(t *testing.T) { resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testContentType), resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testQueries[0].RowID), resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType), - resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.action_type", testNotifications[0].Notification.(EmailNotification).ActionType), + resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testNotifications[0].Notification.(EmailNotification).ConnectionType), ), }, }, @@ -165,11 +165,11 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) { testTriggerTypes[i] = v } testNotificationAction := EmailNotification{ - ActionType: "EmailAction", - Recipients: testRecipients, - Subject: "test tf monitor", - TimeZone: "PST", - MessageBody: "test", + ConnectionType: "Email", + Recipients: testRecipients, + Subject: "test tf monitor", + TimeZone: "PST", + MessageBody: "test", } testNotifications := []MonitorNotification{ { @@ -216,17 +216,17 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) { for i, v := range updatedRecipients { testUpdatedRecipients[i] = v } - updatedTriggerTypes := []string{"Critical"} + updatedTriggerTypes := []string{"Critical", "ResolvedCritical"} testUpdatedTriggerTypes := make([]interface{}, len(updatedTriggerTypes)) for i, v := range updatedTriggerTypes { testUpdatedTriggerTypes[i] = v } testUpdatedNotificationAction := EmailNotification{ - ActionType: "EmailAction", - Recipients: testUpdatedRecipients, - Subject: "test tf monitor", - TimeZone: "PST", - MessageBody: "test", + ConnectionType: "Email", + Recipients: testUpdatedRecipients, + Subject: "test tf monitor", + TimeZone: "PST", + MessageBody: "test", } testUpdatedNotifications := []MonitorNotification{ { @@ -253,7 +253,7 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) { resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testContentType), resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testQueries[0].RowID), resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType), - resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.action_type", testNotifications[0].Notification.(EmailNotification).ActionType), + resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testNotifications[0].Notification.(EmailNotification).ConnectionType), ), }, { @@ -267,7 +267,7 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) { resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testUpdatedContentType), resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testUpdatedQueries[0].RowID), resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testUpdatedTriggers[0].TriggerType), - resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.action_type", testUpdatedNotifications[0].Notification.(EmailNotification).ActionType), + resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testUpdatedNotifications[0].Notification.(EmailNotification).ConnectionType), ), }, }, @@ -371,13 +371,13 @@ resource "sumologic_monitor" "test" { } notifications { notification { - action_type = "EmailAction" + connection_type = "Email" recipients = ["abc@example.com"] subject = "test tf monitor" time_zone = "PST" message_body = "test" } - run_for_trigger_types = ["Critical"] + run_for_trigger_types = ["Critical", "ResolvedCritical"] } }`, testName) } @@ -415,13 +415,13 @@ resource "sumologic_monitor" "test" { } notifications { notification { - action_type = "EmailAction" + connection_type = "Email" recipients = ["abc@example.com"] subject = "test tf monitor" time_zone = "PST" message_body = "test" } - run_for_trigger_types = ["Critical"] + run_for_trigger_types = ["Critical", "ResolvedCritical"] } }`, testName) } diff --git a/sumologic/sumologic_monitors_library_monitor.go b/sumologic/sumologic_monitors_library_monitor.go index 7a7cf40d..16919d96 100644 --- a/sumologic/sumologic_monitors_library_monitor.go +++ b/sumologic/sumologic_monitors_library_monitor.go @@ -141,12 +141,6 @@ type MonitorNotification struct { RunForTriggerTypes []interface{} `json:"runForTriggerTypes"` } -type Notification struct { - ActionType string `json:"actionType,omitempty"` - ConnectionType string `json:"connectionType,omitempty"` - ConnectionID string `json:"connectionId"` -} - type EmailNotification struct { ActionType string `json:"actionType,omitempty"` ConnectionType string `json:"connectionType,omitempty"` From 58c86008569e64092ad7cd9fa036c88f7d9fe82a Mon Sep 17 00:00:00 2001 From: Rohit Sanbhadti Date: Thu, 15 Oct 2020 15:51:27 -0700 Subject: [PATCH 9/9] Update CHANGELOG.md --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99043a01..ced21c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 2.3.2 (October 15, 2020) + +DEPRECATIONS: + +* resource/sumologic_monitor: Deprecated `action_type` in notifications in favor of `connection_type`. (GH-94) + +DOCS: + +* Improved docs for sumologic_monitor resources with webhook connection example + ## 2.3.1 (October 15, 2020) ENHANCEMENTS: