Skip to content

Commit

Permalink
Merge pull request #94 from SumoLogic/rohit-connection-type-fixes
Browse files Browse the repository at this point in the history
fixing action_type connection_type compatibility
  • Loading branch information
rsanbhad authored Oct 15, 2020
2 parents c78d0d8 + 58c8600 commit 56b41a8
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 51 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
60 changes: 46 additions & 14 deletions sumologic/resource_sumologic_monitors_library_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,15 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action_type": {
Type: schema.TypeString,
Optional: 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,
Optional: true,
Computed: true,
},
"subject": {
Type: schema.TypeString,
Expand Down Expand Up @@ -183,7 +186,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {

"description": {
Type: schema.TypeString,
Required: true,
Optional: true,
},

"created_at": {
Expand Down Expand Up @@ -305,19 +308,29 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
schemaInternalNotification := make([]interface{}, 1)
internalNotification := make(map[string]interface{})
internalNotificationDict := n.Notification.(map[string]interface{})
// 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"
}
}
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" {
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)
Expand Down Expand Up @@ -393,20 +406,39 @@ func getNotifications(d *schema.ResourceData) []MonitorNotification {
n := MonitorNotification{}
rawNotificationAction := notificationDict["notification"].([]interface{})
notificationActionDict := rawNotificationAction[0].(map[string]interface{})
if notificationActionDict["action_type"].(string) == "EmailAction" ||
notificationActionDict["action_type"].(string) == "Email" ||
notificationActionDict["connection_type"].(string) == "EmailAction" ||
notificationActionDict["connection_type"].(string) == "Email" {
connectionType := ""
actionType := ""
if notificationActionDict["connection_type"] != nil &&
notificationActionDict["connection_type"] != "" {
connectionType = notificationActionDict["connection_type"].(string)
actionType = connectionType
} 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)
actionType = "EmailAction"
notificationAction.ActionType = actionType
notificationAction.ConnectionType = connectionType
notificationAction.Subject = notificationActionDict["subject"].(string)
notificationAction.Recipients = notificationActionDict["recipients"].([]interface{})
notificationAction.MessageBody = notificationActionDict["message_body"].(string)
notificationAction.TimeZone = notificationActionDict["time_zone"].(string)
n.Notification = notificationAction
} else {
notificationAction := WebhookNotificiation{}
notificationAction.ActionType = notificationActionDict["action_type"].(string)
actionType = "NamedConnectionAction"
notificationAction.ActionType = actionType
notificationAction.ConnectionType = connectionType
notificationAction.ConnectionID = notificationActionDict["connection_id"].(string)
notificationAction.PayloadOverride = notificationActionDict["payload_override"].(string)
n.Notification = notificationAction
Expand Down
48 changes: 24 additions & 24 deletions sumologic/resource_sumologic_monitors_library_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand All @@ -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),
),
},
},
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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{
{
Expand All @@ -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),
),
},
{
Expand All @@ -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),
),
},
},
Expand Down Expand Up @@ -371,13 +371,13 @@ resource "sumologic_monitor" "test" {
}
notifications {
notification {
action_type = "EmailAction"
connection_type = "Email"
recipients = ["[email protected]"]
subject = "test tf monitor"
time_zone = "PST"
message_body = "test"
}
run_for_trigger_types = ["Critical"]
run_for_trigger_types = ["Critical", "ResolvedCritical"]
}
}`, testName)
}
Expand Down Expand Up @@ -415,13 +415,13 @@ resource "sumologic_monitor" "test" {
}
notifications {
notification {
action_type = "EmailAction"
connection_type = "Email"
recipients = ["[email protected]"]
subject = "test tf monitor"
time_zone = "PST"
message_body = "test"
}
run_for_trigger_types = ["Critical"]
run_for_trigger_types = ["Critical", "ResolvedCritical"]
}
}`, testName)
}
Loading

0 comments on commit 56b41a8

Please sign in to comment.