Skip to content

Commit

Permalink
Merge pull request #540 from jurajseffer/datadog_downtime_monitor_tag…
Browse files Browse the repository at this point in the history
…s_sorting

Sort datadog_downtime monitor tags to avoid plan diffs
  • Loading branch information
jirikuncar authored Jul 21, 2020
2 parents c9c8141 + f517a6a commit 8cf1dc9
Show file tree
Hide file tree
Showing 16 changed files with 1,183 additions and 1,087 deletions.
138 changes: 69 additions & 69 deletions datadog/cassettes/TestAccDatadogDowntimeDates.yaml

Large diffs are not rendered by default.

140 changes: 70 additions & 70 deletions datadog/cassettes/TestAccDatadogDowntime_Basic.yaml

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions datadog/cassettes/TestAccDatadogDowntime_BasicMultiScope.yaml

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions datadog/cassettes/TestAccDatadogDowntime_BasicNoRecurrence.yaml

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions datadog/cassettes/TestAccDatadogDowntime_BasicUntilDateRecurrence.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-04-24T23:29:45.950757-04:00
2020-06-15T15:06:16.055349943Z
294 changes: 158 additions & 136 deletions datadog/cassettes/TestAccDatadogDowntime_BasicWithMonitor.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-04-24T23:29:49.030394-04:00
2020-06-15T15:06:18.593606979Z
344 changes: 183 additions & 161 deletions datadog/cassettes/TestAccDatadogDowntime_BasicWithMonitorTags.yaml

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions datadog/cassettes/TestAccDatadogDowntime_TrimWhitespace.yaml

Large diffs are not rendered by default.

270 changes: 135 additions & 135 deletions datadog/cassettes/TestAccDatadogDowntime_Updated.yaml

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions datadog/cassettes/TestAccDatadogDowntime_WeekDayRecurring.yaml

Large diffs are not rendered by default.

217 changes: 131 additions & 86 deletions datadog/cassettes/TestDatadogDowntime_import.yaml

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions datadog/resource_datadog_downtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ func resourceDatadogDowntime() *schema.Resource {
Description: "When specified, this downtime will only apply to this monitor",
},
"monitor_tags": {
Type: schema.TypeList,
// TypeSet makes Terraform ignore differences in order when creating a plan
Type: schema.TypeSet,
Optional: true,
Description: "A list of monitor tags (up to 25), i.e. tags that are applied directly to monitors to which the downtime applies",
// MonitorTags conflicts with MonitorId and it also has a default of `["*"]`, which brings some problems:
// * We can't use DefaultFunc to default to ["*"], since that's incompatible with
// ConflictsWith
// * Since this is a TypeList, DiffSuppressFunc can't really be written well for it
// * Since this is a TypeSet, DiffSuppressFunc can't really be written well for it
// (it is called and expected to give result for each element, not for the whole
// list, so there's no way to tell in each iteration whether the new config value
// is an empty list).
Expand Down Expand Up @@ -273,7 +274,7 @@ func buildDowntimeStruct(authV1 context.Context, d *schema.ResourceData, client
}
dt.SetScope(scope)
var tags []string
for _, mt := range d.Get("monitor_tags").([]interface{}) {
for _, mt := range d.Get("monitor_tags").(*schema.Set).List() {
tags = append(tags, mt.(string))
}
dt.SetMonitorTags(tags)
Expand Down
28 changes: 17 additions & 11 deletions datadog/resource_datadog_downtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func TestAccDatadogDowntime_Basic(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.#", "2"),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.2925324183", "app:webserver"),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.188033227", "service"),
),
},
},
Expand Down Expand Up @@ -130,7 +134,7 @@ func TestAccDatadogDowntime_BasicMultiScope(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -160,7 +164,7 @@ func TestAccDatadogDowntime_BasicNoRecurrence(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -196,7 +200,7 @@ func TestAccDatadogDowntime_BasicUntilDateRecurrence(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -232,7 +236,7 @@ func TestAccDatadogDowntime_BasicUntilOccurrencesRecurrence(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -270,7 +274,7 @@ func TestAccDatadogDowntime_WeekDayRecurring(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -304,7 +308,9 @@ func TestAccDatadogDowntime_Updated(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2925324183", "app:webserver"),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.188033227", "service"),
),
},
{
Expand All @@ -324,7 +330,7 @@ func TestAccDatadogDowntime_Updated(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -358,7 +364,7 @@ func TestAccDatadogDowntime_TrimWhitespace(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -418,7 +424,7 @@ func TestAccDatadogDowntimeDates(t *testing.T) {
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "message", "Example Datadog downtime message."),
resource.TestCheckResourceAttr(
"datadog_downtime.foo", "monitor_tags.0", "*"),
"datadog_downtime.foo", "monitor_tags.2679715827", "*"),
),
},
},
Expand Down Expand Up @@ -493,7 +499,7 @@ resource "datadog_downtime" "foo" {
}
message = "Example Datadog downtime message."
monitor_tags = ["*"]
monitor_tags = ["service", "app:webserver"]
}
`

Expand Down

0 comments on commit 8cf1dc9

Please sign in to comment.