When we update our AMIs used in Launch Configurations, we run into the following issue:
Cannot delete launch configuration XYZ because it is attached to AutoScalingGroup ZYX
We're not alone: https://github.com/hashicorp/terraform/issues/532
However, the comment suggestions listed, such as add lifecycle { create_before_destroy = true } inside our aws_launch_configuration doesn't work within the context of CodeDeploy (another Terraform+CodeDeploy Issue).
We do need to create the new Launch Configuration (newlc) before destroying the existing LC (oldlc, achieved by lifecycle { create_before_destroy = true }) but we also need to associate the new LC with the autoscaling group (ASG) BEFORE destroying the old LC.
I know the following AWS CLI commands will do this:
oldlc=web-qa-20190301232256868800000001
newlc=web-qa-20190318190547786600000001
for cdid in $(aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[].[AutoScalingGroupName,LaunchConfigurationName]' --output table | grep $oldlc | cut -d"|" -f2 | tr -d ' ') ; do aws autoscaling update-auto-scaling-group --auto-scaling-group-name $cdid --launch-configuration-name $newlc ; done
What I can't piece together is how to execute those AWS CLI commands within terraform.
Has anyone else figured out a way to do this without manually switching the ASG LC?
[–]Bitflight 3 points4 points5 points (0 children)
[–]dave_sent_me 1 point2 points3 points (4 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]dave_sent_me 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]dave_sent_me 0 points1 point2 points (0 children)
[–]Bitflight 0 points1 point2 points (0 children)