Skip to content

Commit

Permalink
Merge pull request #550 from SumoLogic/pgupta-terraform-monitor-tags-…
Browse files Browse the repository at this point in the history
…support

SUMO-224653 Adds support for associating tags with Monitor
  • Loading branch information
sumovishal authored Aug 25, 2023
2 parents 2d22ca3 + dbb665a commit 88b6805
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 2.25.1 (Unreleased)
* resource/sumologic_monitor: Added support for associating tags with a Monitor.

## 2.25.0 (August 8, 2023)
FEATURES:
Expand Down
10 changes: 10 additions & 0 deletions sumologic/resource_sumologic_monitors_library_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@ func getMonitorSchema() map[string]*schema.Schema {
Optional: true,
Computed: true,
},

"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}

for k, v := range additionalAttributes {
Expand Down Expand Up @@ -804,6 +812,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
d.Set("alert_name", monitor.AlertName)
d.Set("slo_id", monitor.SloID)
d.Set("notification_group_fields", monitor.NotificationGroupFields)
d.Set("tags", monitor.Tags)

// set notifications
notifications := make([]interface{}, len(monitor.Notifications))
Expand Down Expand Up @@ -1570,6 +1579,7 @@ func resourceToMonitorsLibraryMonitor(d *schema.ResourceData) MonitorsLibraryMon
AlertName: d.Get("alert_name").(string),
SloID: d.Get("slo_id").(string),
NotificationGroupFields: notificationGroupFields,
Tags: d.Get("tags").(map[string]interface{}),
}
}

Expand Down
12 changes: 12 additions & 0 deletions sumologic/resource_sumologic_monitors_library_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.0", testGroupFields[0]),
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.1", testGroupFields[1]),
resource.TestCheckResourceAttr("sumologic_monitor.test", "obj_permission.#", "2"),
resource.TestCheckResourceAttr("sumologic_monitor.test", "tags.application", "sumologic"),
resource.TestCheckResourceAttr("sumologic_monitor.test", "tags.team", "metrics"),
testAccCheckMonitorsLibraryMonitorFGPBackend("sumologic_monitor.test", t, genExpectedPermStmtsMonitor),
),
},
Expand Down Expand Up @@ -512,6 +514,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.0", testGroupFields[0]),
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.1", testGroupFields[1]),
resource.TestCheckResourceAttr("sumologic_monitor.test", "obj_permission.#", "2"),
resource.TestCheckResourceAttr("sumologic_monitor.test", "tags.team", "metrics"),
testAccCheckMonitorsLibraryMonitorFGPBackend("sumologic_monitor.test", t, genExpectedPermStmtsMonitor),
),
},
Expand All @@ -535,6 +538,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.0", testUpdatedGroupFields[0]),
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.1", testUpdatedGroupFields[1]),
resource.TestCheckResourceAttr("sumologic_monitor.test", "obj_permission.#", "1"),
resource.TestCheckResourceAttr("sumologic_monitor.test", "tags.team", "monitor"),
// 1, instead of 2
testAccCheckMonitorsLibraryMonitorFGPBackend("sumologic_monitor.test", t, genExpectedPermStmtsForMonitorUpdate),
),
Expand Down Expand Up @@ -833,6 +837,10 @@ resource "sumologic_monitor" "test" {
}
playbook = "This is a test playbook"
alert_name = "Alert from {{Name}}"
tags = {
team = "metrics"
application = "sumologic"
}
notification_group_fields = ["groupingField1", "groupingField2"]
obj_permission {
subject_type = "role"
Expand Down Expand Up @@ -956,6 +964,10 @@ resource "sumologic_monitor" "test" {
}
playbook = "This is an updated test playbook"
alert_name = "Updated Alert from {{Name}}"
tags = {
team = "monitor"
application = "sumologic"
}
notification_group_fields = ["groupingField3", "groupingField4"]
obj_permission {
subject_type = "role"
Expand Down
53 changes: 27 additions & 26 deletions sumologic/sumologic_monitors_library_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,33 @@ func (s *Client) MoveMonitorsLibraryMonitor(monitorID string, newParentID string

// ---------- TYPES ----------
type MonitorsLibraryMonitor struct {
ID string `json:"id,omitempty"`
IsSystem bool `json:"isSystem"`
Type string `json:"type"`
Queries []MonitorQuery `json:"queries,omitempty"`
ParentID string `json:"parentId"`
Name string `json:"name"`
IsMutable bool `json:"isMutable"`
Version int `json:"version"`
Notifications []MonitorNotification `json:"notifications,omitempty"`
CreatedBy string `json:"createdBy"`
MonitorType string `json:"monitorType"`
EvaluationDelay string `json:"evaluationDelay,omitempty"`
IsLocked bool `json:"isLocked"`
Description string `json:"description"`
CreatedAt string `json:"createdAt"`
Triggers []TriggerCondition `json:"triggers,omitempty"`
ModifiedAt string `json:"modifiedAt"`
ContentType string `json:"contentType"`
ModifiedBy string `json:"modifiedBy"`
IsDisabled bool `json:"isDisabled"`
Status []string `json:"status"`
GroupNotifications bool `json:"groupNotifications"`
Playbook string `json:"playbook,omitempty"`
AlertName string `json:"alertName,omitempty"`
SloID string `json:"sloId,omitempty"`
NotificationGroupFields []string `json:"notificationGroupFields,omitempty"`
ID string `json:"id,omitempty"`
IsSystem bool `json:"isSystem"`
Type string `json:"type"`
Queries []MonitorQuery `json:"queries,omitempty"`
ParentID string `json:"parentId"`
Name string `json:"name"`
IsMutable bool `json:"isMutable"`
Version int `json:"version"`
Notifications []MonitorNotification `json:"notifications,omitempty"`
CreatedBy string `json:"createdBy"`
MonitorType string `json:"monitorType"`
EvaluationDelay string `json:"evaluationDelay,omitempty"`
IsLocked bool `json:"isLocked"`
Description string `json:"description"`
CreatedAt string `json:"createdAt"`
Triggers []TriggerCondition `json:"triggers,omitempty"`
ModifiedAt string `json:"modifiedAt"`
ContentType string `json:"contentType"`
ModifiedBy string `json:"modifiedBy"`
IsDisabled bool `json:"isDisabled"`
Status []string `json:"status"`
GroupNotifications bool `json:"groupNotifications"`
Playbook string `json:"playbook,omitempty"`
AlertName string `json:"alertName,omitempty"`
SloID string `json:"sloId,omitempty"`
NotificationGroupFields []string `json:"notificationGroupFields,omitempty"`
Tags map[string]interface{} `json:"tags"`
}

type MonitorQuery struct {
Expand Down
21 changes: 21 additions & 0 deletions website/docs/r/monitor.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ resource "sumologic_monitor" "tf_logs_monitor_1" {
content_type = "Monitor"
monitor_type = "Logs"
evaluation_delay = "5m"
tags = {
"team" = "monitoring"
"application" = "sumologic"
}
queries {
row_id = "A"
Expand Down Expand Up @@ -110,6 +114,10 @@ resource "sumologic_monitor" "tf_metrics_monitor_1" {
content_type = "Monitor"
monitor_type = "Metrics"
evaluation_delay = "1m"
tags = {
"team" = "monitoring"
"application" = "sumologic"
}
queries {
row_id = "A"
Expand Down Expand Up @@ -160,6 +168,10 @@ resource "sumologic_monitor" "tf_slo_monitor_1" {
monitor_type = "Slo"
slo_id = "0000000000000009"
evaluation_delay = "5m"
tags = {
"team" = "monitoring"
"application" = "sumologic"
}
trigger_conditions {
slo_sli_condition {
Expand Down Expand Up @@ -193,6 +205,10 @@ resource "sumologic_monitor" "tf_slo_monitor_2" {
monitor_type = "Slo"
slo_id = "0000000000000009"
evaluation_delay = "5m"
tags = {
"team" = "monitoring"
"application" = "sumologic"
}
trigger_conditions {
slo_burn_rate_condition {
Expand Down Expand Up @@ -253,6 +269,10 @@ resource "sumologic_monitor" "tf_logs_monitor_2" {
is_disabled = false
content_type = "Monitor"
monitor_type = "Logs"
tags = {
"team" = "monitoring"
"application" = "sumologic"
}
queries {
row_id = "A"
query = "_sourceCategory=event-action info"
Expand Down Expand Up @@ -333,6 +353,7 @@ The following arguments are supported:
- `Logs`: A logs query monitor.
- `Metrics`: A metrics query monitor.
- `Slo`: A SLO based monitor.
- `tags` - (Optional) A map defining tag keys and tag values for the Monitor.
- `evaluation_delay` - (Optional) Evaluation delay as a string consists of the following elements:
1. `<number>`: number of time units,
2. `<time_unit>`: time unit; possible values are: `h` (hour), `m` (minute), `s` (second).
Expand Down

0 comments on commit 88b6805

Please sign in to comment.