@@ -3,6 +3,7 @@ package grafana_test
33import (
44 "encoding/json"
55 "fmt"
6+ "regexp"
67 "testing"
78
89 "github.com/grafana/grafana-openapi-client-go/models"
@@ -320,6 +321,97 @@ func TestAccAlertRule_inOrg(t *testing.T) {
320321 })
321322}
322323
324+ func TestAccAlertRule_nameConflict (t * testing.T ) {
325+ testutils .CheckOSSTestsEnabled (t , ">=9.1.0" )
326+
327+ name := acctest .RandString (10 )
328+
329+ resource .ParallelTest (t , resource.TestCase {
330+ ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
331+ Steps : []resource.TestStep {
332+ {
333+ Config : fmt .Sprintf (`
334+ resource "grafana_organization" "test" {
335+ name = "%[1]s"
336+ }
337+
338+ resource "grafana_folder" "first" {
339+ org_id = grafana_organization.test.id
340+ title = "%[1]s-first"
341+ }
342+
343+ resource "grafana_rule_group" "first" {
344+ org_id = grafana_organization.test.id
345+ name = "%[1]s"
346+ folder_uid = grafana_folder.first.uid
347+ interval_seconds = 60
348+ rule {
349+ name = "My Alert Rule first"
350+ for = "2m"
351+ condition = "B"
352+ no_data_state = "NoData"
353+ exec_err_state = "Alerting"
354+ is_paused = false
355+ data {
356+ ref_id = "A"
357+ query_type = ""
358+ relative_time_range {
359+ from = 600
360+ to = 0
361+ }
362+ datasource_uid = "PD8C576611E62080A"
363+ model = jsonencode({
364+ hide = false
365+ intervalMs = 1000
366+ maxDataPoints = 43200
367+ refId = "A"
368+ })
369+ }
370+ }
371+ }
372+
373+ resource "grafana_folder" "second" {
374+ depends_on = [grafana_rule_group.first]
375+ org_id = grafana_organization.test.id
376+ title = "%[1]s-second"
377+ }
378+
379+ resource "grafana_rule_group" "second" {
380+ org_id = grafana_organization.test.id
381+ name = "%[1]s"
382+ folder_uid = grafana_folder.second.uid
383+ interval_seconds = 60
384+ rule {
385+ name = "My Alert Rule second"
386+ for = "2m"
387+ condition = "B"
388+ no_data_state = "NoData"
389+ exec_err_state = "Alerting"
390+ is_paused = false
391+ data {
392+ ref_id = "A"
393+ query_type = ""
394+ relative_time_range {
395+ from = 600
396+ to = 0
397+ }
398+ datasource_uid = "PD8C576611E62080A"
399+ model = jsonencode({
400+ hide = false
401+ intervalMs = 1000
402+ maxDataPoints = 43200
403+ refId = "A"
404+ })
405+ }
406+ }
407+ }
408+ ` , name ),
409+ ExpectError : regexp .MustCompile (`rule group with name "` + name + `" already exists` ),
410+ },
411+ },
412+ })
413+ }
414+
323415func TestAccAlertRule_disableProvenance (t * testing.T ) {
324416 testutils .CheckOSSTestsEnabled (t , ">=9.1.0" )
325417
0 commit comments