mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix terraform export of notification policy
When exporting a notification policy with no `group_by` the hcl exported is not valid as it is missing the required field. This fixes the issue by initializing the `group_by` field with an empty list if it is nil.
This commit is contained in:
parent
a110917577
commit
8ab12aede4
@ -614,6 +614,10 @@ func exportHcl(download bool, body definitions.AlertingFileExport) response.Resp
|
|||||||
|
|
||||||
for idx, cp := range body.Policies {
|
for idx, cp := range body.Policies {
|
||||||
policy := cp.RouteExport
|
policy := cp.RouteExport
|
||||||
|
if policy.GroupByStr == nil {
|
||||||
|
// required field, must be set to empty array
|
||||||
|
policy.GroupByStr = &[]string{}
|
||||||
|
}
|
||||||
resources = append(resources, hcl.Resource{
|
resources = append(resources, hcl.Resource{
|
||||||
Type: "grafana_notification_policy",
|
Type: "grafana_notification_policy",
|
||||||
Name: fmt.Sprintf("notification_policy_%d", idx+1),
|
Name: fmt.Sprintf("notification_policy_%d", idx+1),
|
||||||
|
@ -1428,6 +1428,23 @@ func TestProvisioningApi(t *testing.T) {
|
|||||||
require.Equal(t, 200, response.Status())
|
require.Equal(t, 200, response.Status())
|
||||||
require.Equal(t, expectedResponse, string(response.Body()))
|
require.Equal(t, expectedResponse, string(response.Body()))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("hcl contains required group_by field", func(t *testing.T) {
|
||||||
|
sut := createProvisioningSrvSut(t)
|
||||||
|
rc := createTestRequestCtx()
|
||||||
|
|
||||||
|
rc.Context.Req.Form.Add("format", "hcl")
|
||||||
|
expectedResponse := "resource \"grafana_notification_policy\" \"notification_policy_1\" {\n" +
|
||||||
|
" contact_point = \"some-receiver\"\n" +
|
||||||
|
" group_by = []\n" +
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
response := sut.RouteGetPolicyTreeExport(&rc)
|
||||||
|
|
||||||
|
t.Log(string(response.Body()))
|
||||||
|
require.Equal(t, 200, response.Status())
|
||||||
|
require.Equal(t, expectedResponse, string(response.Body()))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("mute timings", func(t *testing.T) {
|
t.Run("mute timings", func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user