diff --git a/pkg/services/ngalert/api/api_provisioning.go b/pkg/services/ngalert/api/api_provisioning.go index 4730203e2ae..2736e25fd37 100644 --- a/pkg/services/ngalert/api/api_provisioning.go +++ b/pkg/services/ngalert/api/api_provisioning.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "hash/fnv" "net/http" "strings" @@ -587,11 +588,15 @@ func exportResponse(c *contextmodel.ReqContext, body definitions.AlertingFileExp func exportHcl(download bool, body definitions.AlertingFileExport) response.Response { resources := make([]hcl.Resource, 0, len(body.Groups)+len(body.ContactPoints)+len(body.Policies)+len(body.MuteTimings)) convertToResources := func() error { - for idx, group := range body.Groups { + for _, group := range body.Groups { gr := group + sum := fnv.New64() + _, _ = sum.Write([]byte(gr.Name)) + _, _ = sum.Write([]byte(gr.FolderUID)) + hash := sum.Sum64() resources = append(resources, hcl.Resource{ Type: "grafana_rule_group", - Name: fmt.Sprintf("rule_group_%04d", idx), + Name: fmt.Sprintf("rule_group_%016x", hash), Body: &gr, }) } diff --git a/pkg/services/ngalert/api/api_provisioning_test.go b/pkg/services/ngalert/api/api_provisioning_test.go index 9a05f2bd1ca..b8a9d26523e 100644 --- a/pkg/services/ngalert/api/api_provisioning_test.go +++ b/pkg/services/ngalert/api/api_provisioning_test.go @@ -760,7 +760,7 @@ func TestProvisioningApi(t *testing.T) { insertRule(t, sut, rule1) insertRule(t, sut, createTestAlertRule("rule2", 1)) - expectedResponse := `resource "grafana_rule_group" "rule_group_0000" { + expectedResponse := `resource "grafana_rule_group" "rule_group_cc0954af8a53fa18" { org_id = 1 name = "my-cool-group" folder_uid = "folder-uid" diff --git a/pkg/services/ngalert/api/test-data/post-rulegroup-101-export.hcl b/pkg/services/ngalert/api/test-data/post-rulegroup-101-export.hcl index 0b4ed6338f5..025d519cd50 100644 --- a/pkg/services/ngalert/api/test-data/post-rulegroup-101-export.hcl +++ b/pkg/services/ngalert/api/test-data/post-rulegroup-101-export.hcl @@ -1,4 +1,4 @@ -resource "grafana_rule_group" "rule_group_0000" { +resource "grafana_rule_group" "rule_group_d3e8424bfbf66bc3" { org_id = 1 name = "group101" folder_uid = "e4584834-1a87-4dff-8913-8a4748dfca79"