-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
prevent_destroy should allow plan to succeed #16392
Comments
You're not wrong @beanaroo! Quite a few people have the same issue, but unfortunately the mod's don't seem to agree it is actually a problem 😢 and keep flagging this issue and an 'enhancement'. See #3874 for a two-year long sad tale of frustrated |
Prevent destroy only works if the resource is still included in the script, also dangerous. I've been using it for CodeCommit repositories to have consistent Git repos, but there is no way to prevent it from destructively wiping out an entire Git repo or all of the repos with a mistake. Otherwise resources that have user content that is hard to restore should never be put in Terraform, which is a shame. |
This flag should be renamed to |
It would be useful to have |
@dguisinger yes that is what we are doing, only using terraform for resources that are not calamitous if destroyed. Or in one strategy we have two terraform deployments, with one small one that just creates the stateful resources. The issue is quite a thorn. |
I would like to throw my support behind this being a bug and not merely a desirable enhancement. In my case I have a stateful machine (postgres) that suddenly decided that it needed to be destroyed. I have no idea why since there are no changes in the commit history to anything that affects postgres that I can see. Unfortunately, it is very difficult to debug since I don't know what property it thinks changed. Please mark this as a bug, prevent_destroy is worse than useless as is, it makes terraform actively difficult to use and debug (but is a safety measure that I can't live without, unfortunately). |
Agreed with the consensus in here. If it's not a bug then it's a poorly designed feature that could use some improvement. My team at work tried using it in the past to protect particular resources (like RDS) but the planning issue mentioned above made it useless. It definitely will act as a last line of defense, but it seems implied that you should never try destroying any root module that can reference a prevent_destroy resource in the first place so it's useless. We ended up preventing it with safety checks in our build script and ensuring that we had no production deployments configured to destroy those resources. The other issue with prevent_destroy that we encountered is that you can't selectively apply it to a resource. In one of our applications, we had a Terraform module for an RDS cluster which we wanted to prevent_destroy in production; however, for non-production (testing/staging/etc) accounts, we wanted to reference the same module but allow being destroyed since testing environments can come and go. |
I think my biggest grievance with this bug is that I had to come to Github Issues to find enough information on this. In the documentation on the Terraform website, there are no warnings that I have seen of "Hey, you can include pre-existing S3 buckets and other stateful resources in your Terraform plan. If you do that, Terraform can destroy and recreate those resources if it wants to, or - if you are using If this isn't a bug (which it sounds like it is?), there should be a section in the docs for how to deal with this use-case (immutable stateful storage) and a breakdown of your options:
|
There is also #3874 tracking this discussion as well, one should probably be closed in favor of the other. Ping @jen20 / @phinze / @paddycarver / @radeksimko. |
@ketzacoatl #3874 is the earlier request (2015!) and has the most participants (~40) and +1's (~100), so I would suggest keeping that one. |
^ Also #2159 |
First To the OP, @beanaroo. I agree with you, whether use Second To @whereisaaron (and other guys, I guess?). I think the name of If rename it to what @caruccio said, like So I think what you ask maybe is a new keyword, like So Hi @apparentlymart, what do you think? (Further more, in such a case that the resource becomes |
Thanks @ckyoog If the current |
What's the point of I had the impression that you can freely apply and destroy Terraform described infrastructure, but if you include single |
I think it should show the plan, but still, display an error and return a non-zero exit code. |
@j-martin Agreed - exit codes are there to communicate details about how an action may have failed to other programs; but, if someone runs This includes both the fact that Maybe I intend to destroy that resource at some point, but my Terraform plan is going through a code review process first so that I can squash+merge my code later into master so that Terraform Enterprise can perform the apply for me. In this scenario, yeah, I want |
I have the same issue, caused by aks scale down from 3->1 and scale up from 1->3(triggered from the azure interface). |
We are migrating from 0.11.x to 0.12.x version and I have exactly the same problem with the following versions:
The following
This state define EC2 instance as member of an etcd cluster with a CoreOS image. I tried to replace the My current workaround is to run I have the following error message after running
|
The documentation on https://www.terraform.io/docs/configuration/resources.html#prevent_destroy states:
It's worth noting that when using |
Would a maintainer mind chiming in? This is still an issue in 2020. The current workaround is to temporarily disable prevent_destroy and run terraform plan to see why the destruction is happening, but this is useless for people who only are able to run terraform from inside of a ci/cd environment. |
Although it seems to be the intended behaviour when you remove a resource for it to also remove the prevent_destroy flag and delete protection, it is sometimes risky in the context of CI/CD pipelines. In some cases we keep a central RDS module and individual applications use it, so each application has its own main.tf file where it is called and it sometimes happens where different teams make changes to the code in their repository and run pipelines. We would like to protect the production databases to not be removed by accident even if someone removes the whole RDS resource from their application. |
This is 2021 and nearly 2022 terraform since 0.10 when this issue was opened made a lot of progress but the disability to see the exact reasoned why prevent destroy blocks plan is still the most unpleasant experience with TF. I hope that one day this issue gets closed |
This is a basic e.g. cloudformation feature, and it's critical for things like CMK: you want all gone, except, for instance, RDS snapshots, and the CMK that encrypted them. And you don't want that to block the tear down, you just want those resources to be left behind. |
Throwing my thoughts in here too – we are trying to work out wtf an RDS is claiming to need to be destroyed and recreated. Cannot see the trigger with the current implementation. It should be part of the failure – not only that a prevent_destroy lifecycled resource is needing to be destroyed, buy the why it needs to be destroyed too. |
This brings up a great question... How are people debugging these plans for "unintentional destruction"? |
TBH for me it's been a lot of AWS console work. Edit: to add a little more context. We're using remote modules (via git), so the concept of "swapping the value of |
By swaping the value to |
In our use case, being able to see the plan and understanding why tf is trying to recreate the resource without having to remove the prevent_destroy and risk accidental deletion, would be very useful. |
I noticed this is partially fixed (I'm using v1.4.6). Terraform will now show you what it planned up to (but not including) the |
It's October 2024 and this issue still persists. In my case I want to not re-download the Talos ISO for my schematic-ID EVERYTIME I run Terraform: Snippet of the
|
Terraform Version
0.10.7
Output
Expected Behavior
I would like to know why it wants to destroy it. This is provided when
prevent_destroy
isfalse
by means of(forces new resource)
Actual Behavior
Plan is interrupted before any useful information is displayed.
Steps to Reproduce
terraform init
terraform plan
Important Factoids
Current workaround is to turn
prevent_destroy
off (dangerous!!!) and to runplan
again to see cause. In this case it is due to this open issueThe text was updated successfully, but these errors were encountered: