Skip to content

Commit

Permalink
aws_autoscaling_group: custom diff for overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonaj committed Oct 25, 2023
1 parent 98de67a commit b32f9ec
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ func ResourceGroup() *schema.Resource {
"override": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_requirements": {
Expand Down Expand Up @@ -869,6 +870,7 @@ func ResourceGroup() *schema.Resource {
CustomizeDiff: customdiff.Sequence(
launchTemplateCustomDiff("launch_template", "launch_template.0.name"),
launchTemplateCustomDiff("mixed_instances_policy", "mixed_instances_policy.0.launch_template.0.launch_template_specification.0.launch_template_name"),
launchTemplateCustomDiff("mixed_instances_policy", "mixed_instances_policy.0.launch_template.0.override"),
),
}
}
Expand All @@ -891,7 +893,7 @@ func launchTemplateCustomDiff(baseAttribute, subAttribute string) schema.Customi
}
}

if baseAttribute == "mixed_instances_policy" {
if baseAttribute == "mixed_instances_policy" && !strings.Contains(subAttribute, "override") {
launchTemplate := ba[0].(map[string]interface{})["launch_template"].([]interface{})[0].(map[string]interface{})["launch_template_specification"].([]interface{})[0]
launchTemplateSpecification := launchTemplate.(map[string]interface{})
launchTemplateSpecification["launch_template_id"] = launchTemplateIDUnknown
Expand All @@ -900,6 +902,24 @@ func launchTemplateCustomDiff(baseAttribute, subAttribute string) schema.Customi
return err
}
}

if baseAttribute == "mixed_instances_policy" && strings.Contains(subAttribute, "override") {
log.Printf("[DEBUG] we got here")
launchTemplate := ba[0].(map[string]interface{})["launch_template"].([]interface{})[0].(map[string]interface{})["override"].([]interface{})

for i := range launchTemplate {
key := fmt.Sprintf("mixed_instances_policy.0.launch_template.0.override.%d.launch_template_specification.0.launch_template_name", i)

if diff.HasChange(key) {
launchTemplateSpecification := launchTemplate[i].(map[string]interface{})["launch_template_specification"].([]interface{})[0].(map[string]interface{})
launchTemplateSpecification["launch_template_id"] = launchTemplateIDUnknown
}
}

if err := diff.SetNew(baseAttribute, ba); err != nil {
return err
}
}
}

return nil
Expand Down

0 comments on commit b32f9ec

Please sign in to comment.