Skip to content

Commit

Permalink
azurerm_monitor_smart_detector_alert_rule - Normalize `action_group…
Browse files Browse the repository at this point in the history
….ids`
  • Loading branch information
magodo committed Apr 10, 2024
1 parent 38c1fd7 commit 4b72a21
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 4b72a21

Please sign in to comment.