Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort datadog_downtime monitor tags to avoid plan diffs #540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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 @@ -135,13 +135,14 @@ func resourceDatadogDowntime() *schema.Resource {
Description: "When specified, this downtime will only apply to this monitor",
},
"monitor_tags": {
Type: schema.TypeList,
jirikuncar marked this conversation as resolved.
Show resolved Hide resolved
// 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 @@ -272,7 +273,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", "*"),
jirikuncar marked this conversation as resolved.
Show resolved Hide resolved
),
},
},
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
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -173,6 +175,7 @@ github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI=
Expand Down