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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: prevent_destroy does not prevent destroy when caused by reducing the count #5826

Closed
Gary-Armstrong opened this issue Mar 24, 2016 · 5 comments · Fixed by #9707
Closed
Assignees

Comments

@Gary-Armstrong
Copy link

I do not know if this is a documentation bug or a TF bug or a bug in my expectations.

The situation is that I'm using instance count variables to create/destroy instances. I also am working hard on finding a way to have EIPs persist during instance termination. Well, prevent_destroy = true seems like what I want. Also due to that "diffs don't match" issue, I feel like ignore_changes is also great for me.

So I did this:

resource "aws_eip" "wxmix_test_eip" {
  count = "${var.wxtest_count}"
  depends_on = [ "aws_internet_gateway.main" ]
    instance = "${element(aws_instance.wxtest.*.id, count.index)}"
    vpc = true
  lifecycle {
    prevent_destroy = true
    ignore_changes = ["instance"]
  }
}

I already have 5 test instances. When I plan on reducing to 2 test instances:

terraform plan -var 'wxtest_count=2'
Refreshing Terraform state prior to plan...

null_resource.chef_provision_wxtest.4: Refreshing state... (ID: 1242890369942463320)
null_resource.chef_provision_wxtest.3: Refreshing state... (ID: 5867636346600329267)
null_resource.chef_provision_wxtest.2: Refreshing state... (ID: 6074915431198646171)
...
- aws_eip.wxmix_test_eip.2

- aws_eip.wxmix_test_eip.3

- aws_eip.wxmix_test_eip.4

- aws_instance.wxtest.2

- aws_instance.wxtest.3

- aws_instance.wxtest.4

- null_resource.chef_provision_wxtest.2

- null_resource.chef_provision_wxtest.3

- null_resource.chef_provision_wxtest.4

- null_resource.remote-exec_provision_wxtest.2

- null_resource.remote-exec_provision_wxtest.3

- null_resource.remote-exec_provision_wxtest.4


Plan: 0 to add, 0 to change, 12 to destroy.

This isn't what I expected; the EIP are still being destroyed.

Where does this issue lie? Me, or TF, or the docs?

@catsby
Copy link
Contributor

catsby commented Mar 25, 2016

Hey @Gary-Armstrong thanks for writing in. The core problem here is that prevent_destroy is not preventing destroys caused by reducing the count. I believe this is more a TF core problem, not you at all 😄

@catsby catsby added the core label Mar 25, 2016
@catsby catsby changed the title prevent_destroy on aws_eip does not prevent destroy core: prevent_destroy does not prevent destroy when caused by reducing the count Mar 25, 2016
@Gary-Armstrong
Copy link
Author

Thanks @catsby. Are you clarifying that prevent_destroy will only work in the context of a terraform destroy command? I'd ask that the docs be updated, but I'm not going to suggest that anyone drop core work for docs at this point in the dev cycle.

@radeksimko radeksimko added the bug label Mar 28, 2016
@catsby
Copy link
Contributor

catsby commented Mar 28, 2016

I'm clarifying that prevent_destroy is not working as intended 😄 .

I've re-titled this issue and it should get picked up with other core work. There's another issue regarding ignore_changes that is already getting some work done, and this may be picked up in the process.

Thanks again!

@mitchellh
Copy link
Contributor

Verified this is broken with a test. Working on it now.

@mitchellh mitchellh self-assigned this Oct 29, 2016
mitchellh added a commit that referenced this issue Oct 29, 2016
Fixes #5826

The `prevent_destroy` lifecycle configuration was not being checked when
the count was decreased for a resource with a count. It was only
checking when attributes changed on pre-existing resources.

This fixes that.
gusmat pushed a commit to gusmat/terraform that referenced this issue Dec 6, 2016
Fixes hashicorp#5826

The `prevent_destroy` lifecycle configuration was not being checked when
the count was decreased for a resource with a count. It was only
checking when attributes changed on pre-existing resources.

This fixes that.
@ghost
Copy link

ghost commented Apr 20, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants