Skip to content

Commit

Permalink
Notification Policy: Fix perma-drift
Browse files Browse the repository at this point in the history
Closes #1146

By switching from list to set, the order doesn't matter anymore
  • Loading branch information
julienduchesne committed Nov 16, 2023
1 parent 5abae1f commit 877579b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions examples/resources/grafana_notification_policy/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ resource "grafana_notification_policy" "my_notification_policy" {
match = "="
value = "myvalue"
}
matcher {
label = "alertname"
match = "="
value = "CPU Usage"
}
matcher {
label = "Name"
match = "=~"
value = "host.*|host-b.*"
}
contact_point = grafana_contact_point.a_contact_point.name
continue = true
mute_timings = [grafana_mute_timing.a_mute_timing.name]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func policySchema(depth uint) *schema.Resource {
},
},
"matcher": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Description: "Describes which labels this rule should match. When multiple matchers are supplied, an alert must match ALL matchers to be accepted by this policy. When no matchers are supplied, the rule will match all alert instances.",
Elem: &schema.Resource{
Expand Down Expand Up @@ -341,7 +341,7 @@ func unpackSpecificPolicy(p interface{}) (gapi.SpecificPolicy, error) {
}

if v, ok := json["matcher"]; ok && v != nil {
ms := v.([]interface{})
ms := v.(*schema.Set).List()
matchers := make([]gapi.Matcher, 0, len(ms))
for _, m := range ms {
matcher, err := unpackPolicyMatcher(m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ func TestAccNotificationPolicy_basic(t *testing.T) {
// nested
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.#", "2"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.contact_point", "A Contact Point"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.0.label", "mylabel"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.0.match", "="),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.0.value", "myvalue"),
// Matchers are reordered by the API
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.0.label", "Name"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.0.match", "=~"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.0.value", "host.*|host-b.*"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.1.label", "alertname"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.1.match", "="),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.1.value", "CPU Usage"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.2.label", "mylabel"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.2.match", "="),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.matcher.2.value", "myvalue"),
resource.TestCheckNoResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.group_by"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.continue", "true"),
resource.TestCheckResourceAttr("grafana_notification_policy.my_notification_policy", "policy.0.mute_timings.0", "Some Mute Timing"),
Expand Down

0 comments on commit 877579b

Please sign in to comment.