_This issue was originally opened by @mtb-xt as hashicorp/terraform#13517. It was migrated here as part of the provider split. The original body of the issue is below._
Same issue that was happening in GH-11349 is now happening on terraform 0.9.2
* module.service.aws_launch_configuration.launch_configuration (destroy): 1 error(s) occurred:
* aws_launch_configuration.launch_configuration (deposed hashicorp/terraform#1): 1 error(s) occurred:
* aws_launch_configuration.launch_configuration (deposed hashicorp/terraform#1): ResourceInUse: Cannot delete launch configuration Prod-0073185873a1d1466e73181bd3 because it is attached to AutoScalingGroup Prod-Prod-U15OLDGS3MCV
status code: 400, request id: 68e9849a-1e3a-11e7-a57f-67c69b83858f
We see this with terraform 0.9.6 as well.
Fwiw, I my theory is that this is not aws specific but would affect any resources which need specific ordering but are in separate modules. See https://github.com/hashicorp/terraform/issues/13517#issuecomment-303544598 for test cases.
@mitchellh @stack72 Any thoughts on this issue now that it's been migrated?
I also ran into this in Terraform v0.9.8. I keep getting
* module.qa_environment_blue.aws_launch_configuration.pipeline_1_launch_config (destroy): 1 error(s) occurred:
* aws_launch_configuration.pipeline_1_launch_config: ResourceInUse: Cannot delete launch configuration pipeline-1-launch-config-qa-blue because it is attached to AutoScalingGroup pipeline-1-asg-qa-blue
status code: 400, request id: 63bfbaf0-922e-11e7-972e-6fbb89e5593c
Im having this issue when aws_launch_configuration is used in conjunction with aws_cloudformation_stack, as recommended here to include rolling updates. Obviously, Terraform doesn't know that the LC has an external dependency in the stack. As the stack is still processing the update to ASG, the LC is still needed.
Any chance for a mitigation technique? Perhaps option to delay, defer, postpone, or wait the destruction of the deposed launchconfiguration? I noticed the aws_launch_configuration has no timeouts key. Not quite sure it would work, but maybe a timeouts key would allow consumer to wait the destruction.
Still seeing this in v0.10.7. The ASG and its launch configuration are in the same module. The launch configuration uses the fixed name
attribute, not name_prefix
. It does not have create_before_destroy
set. If I make a change that requires the launch configuration to be recreated, I see this.
Also having the same issue on 0.10.6. LC and ASG are in the same module, no create_before_destroy
set. I have been either tainting the ASG or deleting it in the console to work around.
I'm not sure my case is the same, but here's what I'm observing. I have a LC used by an ASG. We made a change to the IAM instance policy, which requires re-creating the LC.
Our LC has create_before_destroy=true.
The plan wanted to:
It did just that during apply, but this failed because the ASG edit operation succeeds immediately, but isn't actually done immediately. It takes time for the ASG to start using the new LC and abandon the old one. This results in the deletion of LC1 failing.
Re-planning correctly shows that LC1 needs to be deleted as it's now deposed, and applying that new plan after a few minutes succeeds.
I think the issue here is that the provider should poll after changing the LC used by an ASG until the change is effective instead of proceeding immediately.
Hi, i see the same issue in our environment.
Terraform v0.11.1
i can see that the new LC was created and attached to the ASG, but the old LC wasn't delete as it was still attached to the ASG for couple of ms. the end of the plan the new LC is attached to the ASG and i need to run the plan again to delete the old LC.
For me, the issue was the ASG was using name instead of name_prefix. This worked prior to 0.9*.
Switching to name_prefix and ensuring lifecycle { create_before_destroy = true} is set, made it work again.
https://www.terraform.io/docs/providers/aws/r/launch_configuration.html#using-with-autoscaling-groups (see the note about ommitting name, or using name_prefix)
As mentioned by @manos the resource works as intended. The launch configuration is generally immutable and any change practically requires recreation and it's impossible to delete LC without detaching it first. It's also impossible to detach LC from ASG without attaching a new one. That is why it's necessary to use the lifecycle
trick.
The mentioned paragraph in docs should hopefully explain the whole problem:
https://www.terraform.io/docs/providers/aws/r/launch_configuration.html#using-with-autoscaling-groups
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
Still seeing this in v0.10.7. The ASG and its launch configuration are in the same module. The launch configuration uses the fixed
name
attribute, notname_prefix
. It does not havecreate_before_destroy
set. If I make a change that requires the launch configuration to be recreated, I see this.