Skip to content

Commit d79b35b

Browse files
Alerting: Allow duplicated alert rule names (#2323)
* Alerting: Allow duplicated alert rule names * update test * update Grafana version in test
1 parent ae91b09 commit d79b35b

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

internal/resources/grafana/resource_alerting_rule_group.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -427,26 +427,11 @@ func putAlertRuleGroup(ctx context.Context, data *schema.ResourceData, meta inte
427427

428428
// Check if a rule with the same name or uid already exists within the same rule group
429429
for _, r := range rules {
430-
if *r.Title == *ruleToApply.Title {
431-
return retry.NonRetryableError(fmt.Errorf("rule with name %q is defined more than once", *ruleToApply.Title))
432-
}
433430
if ruleToApply.UID != "" && r.UID == ruleToApply.UID {
434431
return retry.NonRetryableError(fmt.Errorf("rule with UID %q is defined more than once. Rules with name %q and %q have the same uid", ruleToApply.UID, *r.Title, *ruleToApply.Title))
435432
}
436433
}
437434

438-
// Check if a rule with the same name already exists within the same folder (changing the ordering is allowed within the same rule group)
439-
for _, existingRule := range respAlertRules.Payload {
440-
if *existingRule.Title == *ruleToApply.Title && *existingRule.FolderUID == *ruleToApply.FolderUID {
441-
if *ruleToApply.RuleGroup == *existingRule.RuleGroup {
442-
break
443-
}
444-
445-
// Retry so that if the user is moving a rule from one group to another, it will pass on the next iteration.
446-
return retry.RetryableError(fmt.Errorf("rule with name %q already exists in the folder", *ruleToApply.Title))
447-
}
448-
}
449-
450435
rules = append(rules, ruleToApply)
451436
}
452437

internal/resources/grafana/resource_alerting_rule_group_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ resource "grafana_rule_group" "second" {
381381
}
382382

383383
func TestAccAlertRule_ruleNameConflict(t *testing.T) {
384-
testutils.CheckOSSTestsEnabled(t, ">=9.1.0")
384+
testutils.CheckOSSTestsEnabled(t, ">=11.6.0")
385385

386386
name := acctest.RandString(10)
387387

@@ -452,7 +452,11 @@ resource "grafana_rule_group" "first" {
452452
}
453453
}
454454
`, name),
455-
ExpectError: regexp.MustCompile(`rule with name "My Alert Rule" is defined more than once`),
455+
Check: resource.ComposeTestCheckFunc(
456+
resource.TestCheckResourceAttr("grafana_rule_group.first", "rule.#", "2"),
457+
resource.TestCheckResourceAttr("grafana_rule_group.first", "rule.0.name", "My Alert Rule"),
458+
resource.TestCheckResourceAttr("grafana_rule_group.first", "rule.1.name", "My Alert Rule"),
459+
),
456460
},
457461
},
458462
})

0 commit comments

Comments
 (0)