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:
Moustafa Baiou
2024-12-31 14:53:39 -05:00
committed by Moustafa Baiou
parent a110917577
commit 8ab12aede4
2 changed files with 21 additions and 0 deletions
@@ -614,6 +614,10 @@ func exportHcl(download bool, body definitions.AlertingFileExport) response.Resp
for idx, cp := range body.Policies {
policy := cp.RouteExport
if policy.GroupByStr == nil {
// required field, must be set to empty array
policy.GroupByStr = &[]string{}
}
resources = append(resources, hcl.Resource{
Type: "grafana_notification_policy",
Name: fmt.Sprintf("notification_policy_%d", idx+1),