Skip to content

Commit 56b41a8

Browse files
authored
Merge pull request #94 from SumoLogic/rohit-connection-type-fixes
fixing action_type connection_type compatibility
2 parents c78d0d8 + 58c8600 commit 56b41a8

File tree

4 files changed

+196
-51
lines changed

4 files changed

+196
-51
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 2.3.2 (October 15, 2020)
2+
3+
DEPRECATIONS:
4+
5+
* resource/sumologic_monitor: Deprecated `action_type` in notifications in favor of `connection_type`. (GH-94)
6+
7+
DOCS:
8+
9+
* Improved docs for sumologic_monitor resources with webhook connection example
10+
111
## 2.3.1 (October 15, 2020)
212

313
ENHANCEMENTS:

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,15 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
133133
Elem: &schema.Resource{
134134
Schema: map[string]*schema.Schema{
135135
"action_type": {
136-
Type: schema.TypeString,
137-
Optional: true,
136+
Type: schema.TypeString,
137+
Optional: true,
138+
Computed: true,
139+
Deprecated: "The field `action_type` is deprecated and will be removed in a future release of the provider - please use `connection_type` instead.",
138140
},
139141
"connection_type": {
140142
Type: schema.TypeString,
141143
Optional: true,
144+
Computed: true,
142145
},
143146
"subject": {
144147
Type: schema.TypeString,
@@ -183,7 +186,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
183186

184187
"description": {
185188
Type: schema.TypeString,
186-
Required: true,
189+
Optional: true,
187190
},
188191

189192
"created_at": {
@@ -305,19 +308,29 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
305308
schemaInternalNotification := make([]interface{}, 1)
306309
internalNotification := make(map[string]interface{})
307310
internalNotificationDict := n.Notification.(map[string]interface{})
311+
// log.Printf("monitor.Notification %v", n.Notification)
308312
if internalNotificationDict["connectionType"] != nil {
309313
internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string)
314+
} else {
315+
// for backwards compatibility
316+
internalNotification["connection_type"] = internalNotificationDict["actionType"].(string)
317+
// convert from old action_type name to new connection_type name if applicable
318+
if internalNotification["connection_type"].(string) == "EmailAction" {
319+
internalNotification["connection_type"] = "Email"
320+
}
321+
if internalNotification["connection_type"].(string) == "NamedConnectionAction" {
322+
internalNotification["connection_type"] = "Webhook"
323+
}
310324
}
311-
internalNotification["action_type"] = internalNotificationDict["actionType"].(string)
312-
if internalNotification["action_type"].(string) == "EmailAction" ||
313-
internalNotification["action_type"].(string) == "Email" ||
314-
internalNotification["connection_type"].(string) == "EmailAction" ||
315-
internalNotification["connection_type"].(string) == "Email" {
325+
if internalNotification["connection_type"].(string) == "Email" {
326+
// for backwards compatibility
327+
internalNotification["action_type"] = "EmailAction"
316328
internalNotification["subject"] = internalNotificationDict["subject"].(string)
317329
internalNotification["recipients"] = internalNotificationDict["recipients"].([]interface{})
318330
internalNotification["message_body"] = internalNotificationDict["messageBody"].(string)
319331
internalNotification["time_zone"] = internalNotificationDict["timeZone"].(string)
320332
} else {
333+
internalNotification["action_type"] = "NamedConnectionAction"
321334
internalNotification["connection_id"] = internalNotificationDict["connectionId"].(string)
322335
if internalNotificationDict["payloadOverride"] != nil {
323336
internalNotification["payload_override"] = internalNotificationDict["payloadOverride"].(string)
@@ -393,20 +406,39 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification {
393406
n := MonitorNotification{}
394407
rawNotificationAction := notificationDict["notification"].([]interface{})
395408
notificationActionDict := rawNotificationAction[0].(map[string]interface{})
396-
if notificationActionDict["action_type"].(string) == "EmailAction" ||
397-
notificationActionDict["action_type"].(string) == "Email" ||
398-
notificationActionDict["connection_type"].(string) == "EmailAction" ||
399-
notificationActionDict["connection_type"].(string) == "Email" {
409+
connectionType := ""
410+
actionType := ""
411+
if notificationActionDict["connection_type"] != nil &&
412+
notificationActionDict["connection_type"] != "" {
413+
connectionType = notificationActionDict["connection_type"].(string)
414+
actionType = connectionType
415+
} else {
416+
// for backwards compatibility
417+
actionType = notificationActionDict["action_type"].(string)
418+
connectionType = actionType
419+
// convert from old action_type name to new connection_type name if applicable
420+
if connectionType == "EmailAction" {
421+
connectionType = "Email"
422+
}
423+
if connectionType == "NamedConnectionAction" {
424+
connectionType = "Webhook"
425+
}
426+
}
427+
if connectionType == "Email" {
400428
notificationAction := EmailNotification{}
401-
notificationAction.ActionType = notificationActionDict["action_type"].(string)
429+
actionType = "EmailAction"
430+
notificationAction.ActionType = actionType
431+
notificationAction.ConnectionType = connectionType
402432
notificationAction.Subject = notificationActionDict["subject"].(string)
403433
notificationAction.Recipients = notificationActionDict["recipients"].([]interface{})
404434
notificationAction.MessageBody = notificationActionDict["message_body"].(string)
405435
notificationAction.TimeZone = notificationActionDict["time_zone"].(string)
406436
n.Notification = notificationAction
407437
} else {
408438
notificationAction := WebhookNotificiation{}
409-
notificationAction.ActionType = notificationActionDict["action_type"].(string)
439+
actionType = "NamedConnectionAction"
440+
notificationAction.ActionType = actionType
441+
notificationAction.ConnectionType = connectionType
410442
notificationAction.ConnectionID = notificationActionDict["connection_id"].(string)
411443
notificationAction.PayloadOverride = notificationActionDict["payload_override"].(string)
412444
n.Notification = notificationAction

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ func TestAccMonitorsLibraryMonitor_create(t *testing.T) {
7474
for i, v := range recipients {
7575
testRecipients[i] = v
7676
}
77-
triggerTypes := []string{"Critical"}
77+
triggerTypes := []string{"Critical", "ResolvedCritical"}
7878
testTriggerTypes := make([]interface{}, len(triggerTypes))
7979
for i, v := range triggerTypes {
8080
testTriggerTypes[i] = v
8181
}
8282
testNotificationAction := EmailNotification{
83-
ActionType: "EmailAction",
84-
Recipients: testRecipients,
85-
Subject: "test tf monitor",
86-
TimeZone: "PST",
87-
MessageBody: "test",
83+
ConnectionType: "Email",
84+
Recipients: testRecipients,
85+
Subject: "test tf monitor",
86+
TimeZone: "PST",
87+
MessageBody: "test",
8888
}
8989
testNotifications := []MonitorNotification{
9090
{
@@ -111,7 +111,7 @@ func TestAccMonitorsLibraryMonitor_create(t *testing.T) {
111111
resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testContentType),
112112
resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testQueries[0].RowID),
113113
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType),
114-
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.action_type", testNotifications[0].Notification.(EmailNotification).ActionType),
114+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testNotifications[0].Notification.(EmailNotification).ConnectionType),
115115
),
116116
},
117117
},
@@ -165,11 +165,11 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) {
165165
testTriggerTypes[i] = v
166166
}
167167
testNotificationAction := EmailNotification{
168-
ActionType: "EmailAction",
169-
Recipients: testRecipients,
170-
Subject: "test tf monitor",
171-
TimeZone: "PST",
172-
MessageBody: "test",
168+
ConnectionType: "Email",
169+
Recipients: testRecipients,
170+
Subject: "test tf monitor",
171+
TimeZone: "PST",
172+
MessageBody: "test",
173173
}
174174
testNotifications := []MonitorNotification{
175175
{
@@ -216,17 +216,17 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) {
216216
for i, v := range updatedRecipients {
217217
testUpdatedRecipients[i] = v
218218
}
219-
updatedTriggerTypes := []string{"Critical"}
219+
updatedTriggerTypes := []string{"Critical", "ResolvedCritical"}
220220
testUpdatedTriggerTypes := make([]interface{}, len(updatedTriggerTypes))
221221
for i, v := range updatedTriggerTypes {
222222
testUpdatedTriggerTypes[i] = v
223223
}
224224
testUpdatedNotificationAction := EmailNotification{
225-
ActionType: "EmailAction",
226-
Recipients: testUpdatedRecipients,
227-
Subject: "test tf monitor",
228-
TimeZone: "PST",
229-
MessageBody: "test",
225+
ConnectionType: "Email",
226+
Recipients: testUpdatedRecipients,
227+
Subject: "test tf monitor",
228+
TimeZone: "PST",
229+
MessageBody: "test",
230230
}
231231
testUpdatedNotifications := []MonitorNotification{
232232
{
@@ -253,7 +253,7 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) {
253253
resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testContentType),
254254
resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testQueries[0].RowID),
255255
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType),
256-
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.action_type", testNotifications[0].Notification.(EmailNotification).ActionType),
256+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testNotifications[0].Notification.(EmailNotification).ConnectionType),
257257
),
258258
},
259259
{
@@ -267,7 +267,7 @@ func TestAccMonitorsLibraryMonitor_update(t *testing.T) {
267267
resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testUpdatedContentType),
268268
resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testUpdatedQueries[0].RowID),
269269
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testUpdatedTriggers[0].TriggerType),
270-
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.action_type", testUpdatedNotifications[0].Notification.(EmailNotification).ActionType),
270+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testUpdatedNotifications[0].Notification.(EmailNotification).ConnectionType),
271271
),
272272
},
273273
},
@@ -371,13 +371,13 @@ resource "sumologic_monitor" "test" {
371371
}
372372
notifications {
373373
notification {
374-
action_type = "EmailAction"
374+
connection_type = "Email"
375375
recipients = ["[email protected]"]
376376
subject = "test tf monitor"
377377
time_zone = "PST"
378378
message_body = "test"
379379
}
380-
run_for_trigger_types = ["Critical"]
380+
run_for_trigger_types = ["Critical", "ResolvedCritical"]
381381
}
382382
}`, testName)
383383
}
@@ -415,13 +415,13 @@ resource "sumologic_monitor" "test" {
415415
}
416416
notifications {
417417
notification {
418-
action_type = "EmailAction"
418+
connection_type = "Email"
419419
recipients = ["[email protected]"]
420420
subject = "test tf monitor"
421421
time_zone = "PST"
422422
message_body = "test"
423423
}
424-
run_for_trigger_types = ["Critical"]
424+
run_for_trigger_types = ["Critical", "ResolvedCritical"]
425425
}
426426
}`, testName)
427427
}

0 commit comments

Comments
 (0)