Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot remove aws_instance source for created AMI #11103

Open
cadavre opened this issue Dec 3, 2019 · 2 comments
Open

Cannot remove aws_instance source for created AMI #11103

cadavre opened this issue Dec 3, 2019 · 2 comments
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. waiting-response Maintainers are waiting on response from community or contributor.

Comments

@cadavre
Copy link

cadavre commented Dec 3, 2019

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Any.

Affected Resource(s)

  • aws_ami_from_instance
  • aws_ami_copy

Terraform Configuration Files

resource "aws_instance" "ami_source" {
  ami           = "ami-0e9e6ba6d3d38faa8"
  instance_type = "t2.micro"
}

resource "aws_ami_from_instance" "my_ami" {
  name               = "my-ami"
  source_instance_id = aws_instance.ami_source.id

  lifecycle {
    prevent_destroy = true # does not prevent destruction
    ignore_changes = ["source_instance_id"] # does not prevent destruction
  }
}

Steps to Reproduce

  1. terraform apply
  2. terraform destroy -target=aws_instance.ami-source

Expected Behavior

Source EC2 instance should be destroyed, but AMI should be kept as after creation it becomes independent resource.

Actual Behavior

Error: Instance cannot be destroyed

  on resources.tf line 144:
 144: resource "aws_ami_from_instance" "my_ami" {

Resource aws_ami_from_instance.my_ami has lifecycle.prevent_destroy set,
but the plan calls for this resource to be destroyed. To avoid this error and
continue with the plan, either disable lifecycle.prevent_destroy or reduce the
scope of the plan using the -target flag.

Removing lifecycle.prevent_destroy produces:

Terraform will perform the following actions:

  # aws_ami_from_instance.my_ami will be destroyed

  # aws_instance.ami_source will be destroyed
@ghost ghost added the service/ec2 Issues and PRs that pertain to the ec2 service. label Dec 3, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 3, 2019
@Broundon
Copy link

Broundon commented Nov 6, 2020

Team,

Is there any update on this issue? i am running into the same problem

@justinretzolk
Copy link
Member

Hey y'all 馃憢 Thank you for taking the time to file this issue. In looking over the configuration, it looks like there's an implicit dependency in the form of the aws_instance.ami_source.id interpolation for source_instance_id that I suspect is the cause of Terraform attempting to destroy the aws_ami_from_instance. I suspect that if you instead hardcoded the source_instance_id value, you wouldn't run into this issue. Can anyone who has experienced this behavior test this to confirm?

@justinretzolk justinretzolk added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. waiting-response Maintainers are waiting on response from community or contributor.
Projects
None yet
Development

No branches or pull requests

3 participants