Skip to content

Commit bfbc406

Browse files
committed
transform old action type to connection type transparently
1 parent 4e854ba commit bfbc406

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,23 +305,31 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
305305
schemaInternalNotification := make([]interface{}, 1)
306306
internalNotification := make(map[string]interface{})
307307
internalNotificationDict := n.Notification.(map[string]interface{})
308-
log.Printf("internalNotificationDict %v", internalNotificationDict)
309-
log.Printf("monitor.Notification %v", n.Notification)
308+
log.Printf("internalNotificationDict before: %v", internalNotificationDict)
309+
// log.Printf("monitor.Notification %v", n.Notification)
310310
if internalNotificationDict["connectionType"] != nil {
311311
internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string)
312+
} else {
313+
// for backwards compatibility
314+
internalNotification["connection_type"] = internalNotificationDict["actionType"].(string)
315+
// convert from old action_type name to new connection_type name if applicable
316+
if internalNotification["connection_type"].(string) == "EmailAction" {
317+
internalNotification["connection_type"] = "Email"
318+
}
319+
if internalNotification["connection_type"].(string) == "NamedConnectionAction" {
320+
internalNotification["connection_type"] = "Webhook"
321+
}
312322
}
313-
if internalNotificationDict["actionType"] != nil {
314-
internalNotification["action_type"] = internalNotificationDict["actionType"].(string)
315-
}
316-
if internalNotification["action_type"].(string) == "EmailAction" ||
317-
internalNotification["action_type"].(string) == "Email" ||
318-
internalNotification["connection_type"].(string) == "EmailAction" ||
319-
internalNotification["connection_type"].(string) == "Email" {
323+
log.Printf("internalNotification after fixing: %v", internalNotification)
324+
if internalNotification["connection_type"].(string) == "Email" {
325+
// for backwards compatibility
326+
internalNotification["action_type"] = "EmailAction"
320327
internalNotification["subject"] = internalNotificationDict["subject"].(string)
321328
internalNotification["recipients"] = internalNotificationDict["recipients"].([]interface{})
322329
internalNotification["message_body"] = internalNotificationDict["messageBody"].(string)
323330
internalNotification["time_zone"] = internalNotificationDict["timeZone"].(string)
324331
} else {
332+
internalNotification["action_type"] = "NamedConnectionAction"
325333
internalNotification["connection_id"] = internalNotificationDict["connectionId"].(string)
326334
if internalNotificationDict["payloadOverride"] != nil {
327335
internalNotification["payload_override"] = internalNotificationDict["payloadOverride"].(string)
@@ -398,10 +406,7 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification {
398406
rawNotificationAction := notificationDict["notification"].([]interface{})
399407
notificationActionDict := rawNotificationAction[0].(map[string]interface{})
400408
log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict)
401-
if notificationActionDict["action_type"].(string) == "EmailAction" ||
402-
notificationActionDict["action_type"].(string) == "Email" ||
403-
notificationActionDict["connection_type"].(string) == "EmailAction" ||
404-
notificationActionDict["connection_type"].(string) == "Email" {
409+
if notificationActionDict["connection_type"].(string) == "Email" {
405410
notificationAction := EmailNotification{}
406411
notificationAction.ActionType = notificationActionDict["action_type"].(string)
407412
notificationAction.ConnectionType = notificationActionDict["connection_type"].(string)

0 commit comments

Comments
 (0)