Open hashibot opened 7 years ago
This is critical for ASG's that reference the old AMI. If you deregister the AMI, the ASG fails to launch any more instances.
Let me show another example where it's useful.
Assuming I've added resources to create an EBS-backed EC2 instance, provision it and then wants to make an AMI from it. I'm using aws_ami_from_instance
. After AMI is done I want to remove resources like security group, ssh keypair and EC2 instance itself, but keep AMI that I've created.
If I add lifecycle prevent_destroy
to aws_ami_from_instance
and make terraform destroy -target=aws_instance.my_source
– it wants to remove both: EC2 instance and AMI, which is IMHO incorrect.
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.
If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!
Reactivating this issue. There should be no reason why an AMI, created from an instance, should be destroyed when the original instance is destroyed. Not only does this affect ASGs, but it also seems to fly in the face of destroying only those resources that are targeted for destruction.
I see skip_destroy has made its way into several resources, could it be added to this as well?
Another related issue is when you create a new AMI it deletes the previous AMI for some reason. It should be possible to create multiple amis from one EC2, without affected any previous images
What is the resolution to this problem?
I just ran into it when using Terraform to create new versions of launch templates from an instance I use for a staging / build environment. I wasn't aware that it'd been deleting previous version AMIs each time it's executed leaving those versions without an AMI
This issue was originally opened by @dhoer as hashicorp/terraform#14841. It was migrated here as part of the provider split. The original body of the issue is below.
I want to keep the previous AMI created by aws_ami_from_instance, but it does a destroy first. It would be nice to add
skip_destroy
attribute that would allow for skipping the removal of the previous AMI created from instance.