Skip to content

Commit

Permalink
Rename rules field to rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweav committed Aug 23, 2022
1 parent e4d204b commit b731dfd
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "grafana_alert_rule" "my_multi_alert_group" {
folder_uid = grafana_folder.compound_rule_folder.uid
interval_seconds = 240
org_id = 1
rules {
rule {
name = "My Alert Rule 1"
for = "2m"
condition = "B"
Expand Down Expand Up @@ -83,7 +83,7 @@ EOT
}
}

rules {
rule {
name = "My Alert Rule 2"
for = "4m"
condition = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "grafana_alert_rule" "my_multi_alert_group" {
folder_uid = grafana_folder.compound_rule_folder.uid
interval_seconds = 240
org_id = 1
rules {
rule {
name = "My Alert Rule 1"
for = "2m"
condition = "B"
Expand Down Expand Up @@ -83,7 +83,7 @@ EOT
}
}

rules {
rule {
name = "My Alert Rule 2"
for = "4m"
condition = "B"
Expand Down Expand Up @@ -159,7 +159,7 @@ EOT
}
}

rules {
rule {
name = "My Alert Rule 3"
for = "4m"
condition = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "grafana_alert_rule" "my_multi_alert_group" {
folder_uid = grafana_folder.compound_rule_folder.uid
interval_seconds = 240
org_id = 1
rules {
rule {
name = "My Alert Rule 1"
for = "2m"
condition = "B"
Expand Down Expand Up @@ -83,7 +83,7 @@ EOT
}
}

rules {
rule {
name = "My Alert Rule 2"
for = "4m"
condition = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource "grafana_alert_rule" "my_alert_rule" {
folder_uid = grafana_folder.rule_folder_2.uid
interval_seconds = 240
org_id = 1
rules {
rule {
name = "My Alert Rule 1"
for = "2m"
condition = "B"
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/grafana_alert_rule/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "grafana_alert_rule" "my_alert_rule" {
folder_uid = grafana_folder.rule_folder.uid
interval_seconds = 240
org_id = 1
rules {
rule {
name = "My Alert Rule 1"
for = "2m"
condition = "B"
Expand Down
6 changes: 3 additions & 3 deletions grafana/resource_alerting_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Manages Grafana Alerting rule groups.
ForceNew: true,
Description: "The ID of the org to which the group belongs.",
},
"rules": {
"rule": {
Type: schema.TypeList,
Required: true,
Description: "The rules within the group.",
Expand Down Expand Up @@ -274,15 +274,15 @@ func packRuleGroup(g gapi.RuleGroup, data *schema.ResourceData) error {
}
rules = append(rules, packed)
}
data.Set("rules", rules)
data.Set("rule", rules)
return nil
}

func unpackRuleGroup(data *schema.ResourceData) (gapi.RuleGroup, error) {
group := data.Get("name").(string)
folder := data.Get("folder_uid").(string)
interval := data.Get("interval_seconds").(int)
packedRules := data.Get("rules").([]interface{})
packedRules := data.Get("rule").([]interface{})
orgID := data.Get("org_id").(int)

rules := make([]gapi.AlertRule, 0, len(packedRules))
Expand Down
44 changes: 22 additions & 22 deletions grafana/resource_alerting_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccAlertRule_basic(t *testing.T) {
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "name", "My Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "interval_seconds", "240"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "org_id", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.#", "1"),
),
},
// Test import.
Expand All @@ -47,9 +47,9 @@ func TestAccAlertRule_basic(t *testing.T) {
testRuleGroupCheckExists("grafana_alert_rule.my_alert_rule", &group),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "name", "My Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "interval_seconds", "240"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.0.name", "A Different Rule"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.0.for", "2m"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.0.name", "A Different Rule"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.0.for", "2m"),
),
},
// Test rename group.
Expand All @@ -61,9 +61,9 @@ func TestAccAlertRule_basic(t *testing.T) {
testRuleGroupCheckExists("grafana_alert_rule.my_alert_rule", &group),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "name", "A Different Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "interval_seconds", "240"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.0.for", "2m"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.0.for", "2m"),
),
},
// Test change interval.
Expand All @@ -75,7 +75,7 @@ func TestAccAlertRule_basic(t *testing.T) {
testRuleGroupCheckExists("grafana_alert_rule.my_alert_rule", &group),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "name", "My Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "interval_seconds", "360"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.#", "1"),
),
},
// Test re-parent folder.
Expand All @@ -86,9 +86,9 @@ func TestAccAlertRule_basic(t *testing.T) {
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "name", "My Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "interval_seconds", "240"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "folder_uid", "test-uid"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rules.0.for", "2m"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.#", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_alert_rule", "rule.0.for", "2m"),
),
},
},
Expand All @@ -114,7 +114,7 @@ func TestAccAlertRule_compound(t *testing.T) {
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "name", "My Multi-Alert Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "interval_seconds", "240"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "org_id", "1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.#", "2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.#", "2"),
),
},
// Test import.
Expand All @@ -131,9 +131,9 @@ func TestAccAlertRule_compound(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testRuleGroupCheckExists("grafana_alert_rule.my_multi_alert_group", &group),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "name", "My Multi-Alert Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.#", "2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.0.name", "My Alert asdf"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.1.name", "My Alert Rule 2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.#", "2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.0.name", "My Alert asdf"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.1.name", "My Alert Rule 2"),
),
},
// Test addition of a rule to an existing group.
Expand All @@ -142,10 +142,10 @@ func TestAccAlertRule_compound(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testRuleGroupCheckExists("grafana_alert_rule.my_multi_alert_group", &group),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "name", "My Multi-Alert Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.#", "3"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.1.name", "My Alert Rule 2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.2.name", "My Alert Rule 3"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.#", "3"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.1.name", "My Alert Rule 2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.2.name", "My Alert Rule 3"),
),
},
// Test removal of rules from an existing group.
Expand All @@ -154,9 +154,9 @@ func TestAccAlertRule_compound(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testRuleGroupCheckExists("grafana_alert_rule.my_multi_alert_group", &group),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "name", "My Multi-Alert Rule Group"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.#", "2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rules.1.name", "My Alert Rule 2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.#", "2"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.0.name", "My Alert Rule 1"),
resource.TestCheckResourceAttr("grafana_alert_rule.my_multi_alert_group", "rule.1.name", "My Alert Rule 2"),
),
},
},
Expand Down

0 comments on commit b731dfd

Please sign in to comment.