From 4b72a21e86224698854dc1375f3bff3abd54f367 Mon Sep 17 00:00:00 2001 From: magodo Date: Wed, 10 Apr 2024 14:15:43 +0800 Subject: [PATCH] `azurerm_monitor_smart_detector_alert_rule` - Normalize `action_group.ids` --- ...itor_smart_detector_alert_rule_resource.go | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/services/monitor/monitor_smart_detector_alert_rule_resource.go b/internal/services/monitor/monitor_smart_detector_alert_rule_resource.go index 96c713dd7ad3..7dc59c04be17 100644 --- a/internal/services/monitor/monitor_smart_detector_alert_rule_resource.go +++ b/internal/services/monitor/monitor_smart_detector_alert_rule_resource.go @@ -19,6 +19,7 @@ import ( commonValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor/migration" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/set" @@ -251,7 +252,11 @@ func resourceMonitorSmartDetectorAlertRuleRead(d *pluginsdk.ResourceData, meta i } d.Set("throttling_duration", throttlingDuration) - if err := d.Set("action_group", flattenMonitorSmartDetectorAlertRuleActionGroup(&props.ActionGroups)); err != nil { + actionGroup, err := flattenMonitorSmartDetectorAlertRuleActionGroup(&props.ActionGroups) + if err != nil { + return fmt.Errorf("flatten `action_group`: %+v", err) + } + if err := d.Set("action_group", actionGroup); err != nil { return fmt.Errorf("setting `action_group`: %+v", err) } } @@ -288,9 +293,9 @@ func expandMonitorSmartDetectorAlertRuleActionGroup(input []interface{}) *smartd } } -func flattenMonitorSmartDetectorAlertRuleActionGroup(input *smartdetectoralertrules.ActionGroupsInformation) []interface{} { +func flattenMonitorSmartDetectorAlertRuleActionGroup(input *smartdetectoralertrules.ActionGroupsInformation) ([]interface{}, error) { if input == nil { - return []interface{}{} + return []interface{}{}, nil } var customEmailSubject, CustomWebhookPayload string @@ -301,11 +306,20 @@ func flattenMonitorSmartDetectorAlertRuleActionGroup(input *smartdetectoralertru CustomWebhookPayload = *input.CustomWebhookPayload } + var groupIds []string + for _, idRaw := range input.GroupIds { + id, err := parse.ActionGroupIDInsensitively(idRaw) + if err != nil { + return nil, fmt.Errorf("parsing %s: %v", idRaw, err) + } + groupIds = append(groupIds, id.ID()) + } + return []interface{}{ map[string]interface{}{ - "ids": input.GroupIds, + "ids": groupIds, "email_subject": customEmailSubject, "webhook_payload": CustomWebhookPayload, }, - } + }, nil }