diff --git a/CHANGELOG.md b/CHANGELOG.md index e09bd57d..3c619325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/sumologic/resource_sumologic_monitors_library_monitor.go b/sumologic/resource_sumologic_monitors_library_monitor.go index 15b96c10..5ae9b73a 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor.go +++ b/sumologic/resource_sumologic_monitors_library_monitor.go @@ -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 { @@ -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)) @@ -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{}), } } diff --git a/sumologic/resource_sumologic_monitors_library_monitor_test.go b/sumologic/resource_sumologic_monitors_library_monitor_test.go index 7a04874a..2502207c 100644 --- a/sumologic/resource_sumologic_monitors_library_monitor_test.go +++ b/sumologic/resource_sumologic_monitors_library_monitor_test.go @@ -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), ), }, @@ -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), ), }, @@ -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), ), @@ -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" @@ -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" diff --git a/sumologic/sumologic_monitors_library_monitor.go b/sumologic/sumologic_monitors_library_monitor.go index a5ceab97..7fbd2c38 100644 --- a/sumologic/sumologic_monitors_library_monitor.go +++ b/sumologic/sumologic_monitors_library_monitor.go @@ -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 { diff --git a/website/docs/r/monitor.html.markdown b/website/docs/r/monitor.html.markdown index 03a6a505..e5b7f973 100644 --- a/website/docs/r/monitor.html.markdown +++ b/website/docs/r/monitor.html.markdown @@ -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" @@ -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" @@ -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 { @@ -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 { @@ -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" @@ -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 of time units, 2. ``: time unit; possible values are: `h` (hour), `m` (minute), `s` (second).