Skip to content

Commit

Permalink
[datadog_monitor] Fix unsetting of restricted_roles (#1970)
Browse files Browse the repository at this point in the history
* add support for removing roles

* update docs

* cleanup

* record cassettes
  • Loading branch information
skarimo authored Jun 16, 2023
1 parent 8d535e3 commit a9a73d6
Show file tree
Hide file tree
Showing 54 changed files with 1,432 additions and 1,125 deletions.
6 changes: 3 additions & 3 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func updateDashboardState(d *schema.ResourceData, dashboard *datadogV1.Dashboard
}

// Set notify list
notifyList := buildTerraformNotifyList(&dashboard.NotifyList)
notifyList := buildTerraformNotifyList(dashboard.NotifyList.Get())
if err := d.Set("notify_list", notifyList); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -377,11 +377,11 @@ func buildDatadogDashboard(d *schema.ResourceData) (*datadogV1.Dashboard, error)

// Build NotifyList
notifyList := d.Get("notify_list").(*schema.Set)
dashboard.NotifyList = *buildDatadogNotifyList(notifyList)
dashboard.SetNotifyList(*buildDatadogNotifyList(notifyList))

// Build Tags
tags := utils.GetStringSlice(d, "tags")
dashboard.Tags = tags
dashboard.SetTags(tags)

// Build TemplateVariables
templateVariables := d.Get("template_variable").([]interface{})
Expand Down
2 changes: 1 addition & 1 deletion datadog/resource_datadog_downtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func updateDowntimeState(d *schema.ResourceData, dt downtimeOrDowntimeChild, upd
}
if r.GetWeekDays() != nil {
weekDays := make([]string, 0, len(r.GetWeekDays()))
weekDays = append(weekDays, r.WeekDays...)
weekDays = append(weekDays, *r.WeekDays.Get()...)
recurrence["week_days"] = weekDays
}
if attr, ok := r.GetRruleOk(); ok {
Expand Down
11 changes: 4 additions & 7 deletions datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,15 @@ func buildMonitorStruct(d utils.Resource) (*datadogV1.Monitor, *datadogV1.Monito
u.SetPriority(int64(d.Get("priority").(int)))
u.SetOptions(o)

roles := make([]string, 0)
var roles []string
if attr, ok := d.GetOk("restricted_roles"); ok {
for _, r := range attr.(*schema.Set).List() {
roles = append(roles, r.(string))
}
sort.Strings(roles)
m.SetRestrictedRoles(roles)
u.SetRestrictedRoles(roles)
} else {
m.SetRestrictedRoles(nil)
u.SetRestrictedRoles(nil)
}
m.SetRestrictedRoles(roles)
u.SetRestrictedRoles(roles)

tags := make([]string, 0)
if attr, ok := d.GetOk("tags"); ok {
Expand Down Expand Up @@ -974,7 +971,7 @@ func updateMonitorState(d *schema.ResourceData, meta interface{}, m *datadogV1.M
return diag.FromErr(err)
}

if restrictedRoles, ok := m.GetRestrictedRolesOk(); ok && len(*restrictedRoles) > 0 {
if restrictedRoles, ok := m.GetRestrictedRolesOk(); ok && restrictedRoles != nil && len(*restrictedRoles) > 0 {
// This helper function is defined in `resource_datadog_dashboard`
restrictedRolesCopy := buildTerraformRestrictedRoles(restrictedRoles)
if err := d.Set("restricted_roles", restrictedRolesCopy); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-04-21T12:26:31.94407-04:00
2023-06-16T12:02:14.869121-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-04-21T12:24:41.180751-04:00
2023-06-16T12:02:26.549562-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-07-05T09:13:06.879261-04:00
2023-06-16T12:00:53.754-04:00
415 changes: 240 additions & 175 deletions datadog/tests/cassettes/TestAccDatadogMonitorDatasource.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-07-05T09:13:06.88117-04:00
2023-06-16T11:54:38.003849-04:00

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/tests/cassettes/TestAccDatadogMonitor_Basic.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-02-01T08:36:54.245646-05:00
2023-06-16T11:54:25.335103-04:00
36 changes: 18 additions & 18 deletions datadog/tests/cassettes/TestAccDatadogMonitor_Basic.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-02-01T08:36:54.245637-05:00
2023-06-16T11:54:51.844337-04:00
36 changes: 18 additions & 18 deletions datadog/tests/cassettes/TestAccDatadogMonitor_BasicNoTreshold.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-02-01T08:36:54.245641-05:00
2023-06-16T11:55:32.4208-04:00
78 changes: 39 additions & 39 deletions datadog/tests/cassettes/TestAccDatadogMonitor_Basic_float_int.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-07-05T09:13:24.304065-04:00
2023-06-16T11:56:44.238284-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-09-01T15:20:20.833679-04:00
2023-06-16T11:56:58.179741-04:00
37 changes: 20 additions & 17 deletions datadog/tests/cassettes/TestAccDatadogMonitor_FormulaFunction.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/tests/cassettes/TestAccDatadogMonitor_Log.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-07-05T09:13:17.992984-04:00
2023-06-16T11:55:48.981842-04:00
63 changes: 36 additions & 27 deletions datadog/tests/cassettes/TestAccDatadogMonitor_Log.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-10-13T16:16:16.660353-07:00
2023-06-16T11:55:48.98187-04:00
36 changes: 18 additions & 18 deletions datadog/tests/cassettes/TestAccDatadogMonitor_LogMultiAlert.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-08-16T16:36:58.849386-04:00
2023-06-16T11:56:03.611376-04:00

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-07-05T09:13:17.72545-04:00
2023-06-16T11:57:24.075444-04:00
184 changes: 112 additions & 72 deletions datadog/tests/cassettes/TestAccDatadogMonitor_RestrictedRoles.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-01-13T10:16:29.791143-05:00
2023-06-16T11:57:38.988748-04:00
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 1
interactions:
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
Expand All @@ -23,7 +23,7 @@ interactions:
duration: ""
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
Expand All @@ -43,7 +43,7 @@ interactions:
duration: ""
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
Expand All @@ -63,7 +63,7 @@ interactions:
duration: ""
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
Expand All @@ -74,7 +74,7 @@ interactions:
method: POST
response:
body: |
{"id":107793552,"org_id":321813,"type":"query alert","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","message":"a message","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} > 0.5","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_audit":false,"silenced":{}},"multi":false,"created_at":1673622991000,"created":"2023-01-13T15:16:31.166641+00:00","modified":"2023-01-13T15:16:31.166641+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}}
{"id":122222571,"org_id":321813,"type":"query alert","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","message":"a message","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} > 0.5","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_audit":false,"silenced":{}},"multi":false,"created_at":1686931060000,"created":"2023-06-16T15:57:40.414188+00:00","modified":"2023-06-16T15:57:40.414188+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}}
headers:
Content-Type:
- application/json
Expand All @@ -87,11 +87,11 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552
url: https://api.datadoghq.com/api/v1/monitor/122222571
method: GET
response:
body: |
{"id":107793552,"org_id":321813,"type":"query alert","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","message":"a message","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} > 0.5","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_audit":false,"silenced":{}},"multi":false,"created_at":1673622991000,"created":"2023-01-13T15:16:31.166641+00:00","modified":"2023-01-13T15:16:31.166641+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}}
{"id":122222571,"org_id":321813,"type":"query alert","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","message":"a message","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} > 0.5","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_audit":false,"silenced":{}},"multi":false,"created_at":1686931060000,"created":"2023-06-16T15:57:40.414188+00:00","modified":"2023-06-16T15:57:40.414188+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}}
headers:
Content-Type:
- application/json
Expand All @@ -100,14 +100,14 @@ interactions:
duration: ""
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552/validate
url: https://api.datadoghq.com/api/v1/monitor/122222571/validate
method: POST
response:
body: |
Expand All @@ -124,11 +124,11 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552
url: https://api.datadoghq.com/api/v1/monitor/122222571
method: GET
response:
body: |
{"id":107793552,"org_id":321813,"type":"query alert","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","message":"a message","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} > 0.5","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_audit":false,"silenced":{}},"multi":false,"created_at":1673622991000,"created":"2023-01-13T15:16:31.166641+00:00","modified":"2023-01-13T15:16:31.166641+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}}
{"id":122222571,"org_id":321813,"type":"query alert","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","message":"a message","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} > 0.5","options":{"include_tags":true,"new_host_delay":300,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_audit":false,"silenced":{}},"multi":false,"created_at":1686931060000,"created":"2023-06-16T15:57:40.414188+00:00","modified":"2023-06-16T15:57:40.414188+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}}
headers:
Content-Type:
- application/json
Expand All @@ -137,14 +137,14 @@ interactions:
duration: ""
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552/validate
url: https://api.datadoghq.com/api/v1/monitor/122222571/validate
method: POST
response:
body: |
Expand All @@ -157,14 +157,14 @@ interactions:
duration: ""
- request:
body: |
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1673622989","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","tags":[],"type":"metric alert"}
{"message":"a message","name":"tf-TestAccDatadogMonitor_SchedulingOptions-local-1686931058","options":{"include_tags":true,"new_host_delay":300,"no_data_timeframe":10,"notify_no_data":false,"require_full_window":true,"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"priority":3,"query":"avg(current_1mo):avg:system.load.5{*} \u003e 0.5","restricted_roles":null,"tags":[],"type":"metric alert"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552/validate
url: https://api.datadoghq.com/api/v1/monitor/122222571/validate
method: POST
response:
body: |
Expand All @@ -181,11 +181,11 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552
url: https://api.datadoghq.com/api/v1/monitor/122222571
method: DELETE
response:
body: |
{"deleted_monitor_id":107793552}
{"deleted_monitor_id":122222571}
headers:
Content-Type:
- application/json
Expand All @@ -198,7 +198,7 @@ interactions:
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v1/monitor/107793552
url: https://api.datadoghq.com/api/v1/monitor/122222571
method: GET
response:
body: '{"errors":["Monitor not found"]}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-04-19T10:53:16.708557-04:00
2023-06-16T11:57:38.988748-04:00
Loading

0 comments on commit a9a73d6

Please sign in to comment.