Skip to content

Commit 17f65b7

Browse files
committed
fixing create to be in parity with read
1 parent bfbc406 commit 17f65b7

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ 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 before: %v", internalNotificationDict)
308+
log.Printf("[ROHIT DEBUG] internalNotificationDict before: %v", internalNotificationDict)
309309
// log.Printf("monitor.Notification %v", n.Notification)
310310
if internalNotificationDict["connectionType"] != nil {
311311
internalNotification["connection_type"] = internalNotificationDict["connectionType"].(string)
@@ -320,7 +320,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
320320
internalNotification["connection_type"] = "Webhook"
321321
}
322322
}
323-
log.Printf("internalNotification after fixing: %v", internalNotification)
323+
log.Printf("[ROHIT DEBUG] internalNotification after fixing: %v", internalNotification)
324324
if internalNotification["connection_type"].(string) == "Email" {
325325
// for backwards compatibility
326326
internalNotification["action_type"] = "EmailAction"
@@ -405,25 +405,42 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification {
405405
n := MonitorNotification{}
406406
rawNotificationAction := notificationDict["notification"].([]interface{})
407407
notificationActionDict := rawNotificationAction[0].(map[string]interface{})
408+
var connectionType string
409+
var actionType string
408410
log.Printf("[ROHIT DEBUG] notificationActionDict: %v", notificationActionDict)
409-
if notificationActionDict["connection_type"].(string) == "Email" {
411+
if notificationActionDict["connection_type"] != nil {
412+
connectionType = notificationActionDict["connection_type"].(string)
413+
} else {
414+
// for backwards compatibility
415+
actionType = notificationActionDict["action_type"].(string)
416+
connectionType = actionType
417+
// convert from old action_type name to new connection_type name if applicable
418+
if connectionType == "EmailAction" {
419+
connectionType = "Email"
420+
}
421+
if connectionType == "NamedConnectionAction" {
422+
connectionType = "Webhook"
423+
}
424+
}
425+
if connectionType == "Email" {
410426
notificationAction := EmailNotification{}
411-
notificationAction.ActionType = notificationActionDict["action_type"].(string)
412-
notificationAction.ConnectionType = notificationActionDict["connection_type"].(string)
427+
notificationAction.ActionType = actionType
428+
notificationAction.ConnectionType = connectionType
413429
notificationAction.Subject = notificationActionDict["subject"].(string)
414430
notificationAction.Recipients = notificationActionDict["recipients"].([]interface{})
415431
notificationAction.MessageBody = notificationActionDict["message_body"].(string)
416432
notificationAction.TimeZone = notificationActionDict["time_zone"].(string)
417433
n.Notification = notificationAction
418434
} else {
419435
notificationAction := WebhookNotificiation{}
420-
notificationAction.ActionType = notificationActionDict["action_type"].(string)
421-
notificationAction.ConnectionType = notificationActionDict["connection_type"].(string)
436+
notificationAction.ActionType = actionType
437+
notificationAction.ConnectionType = connectionType
422438
notificationAction.ConnectionID = notificationActionDict["connection_id"].(string)
423439
notificationAction.PayloadOverride = notificationActionDict["payload_override"].(string)
424440
n.Notification = notificationAction
425441
}
426442
n.RunForTriggerTypes = notificationDict["run_for_trigger_types"].([]interface{})
443+
log.Printf("[ROHIT DEBUG] Notification object: %v", n.Notification)
427444
notifications[i] = n
428445
}
429446
return notifications

0 commit comments

Comments
 (0)