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

Allow Terraform to not crash when prevent_destroy is enabled #32943

Closed
FranksRobins opened this issue Mar 30, 2023 · 3 comments
Closed

Allow Terraform to not crash when prevent_destroy is enabled #32943

FranksRobins opened this issue Mar 30, 2023 · 3 comments
Labels
duplicate issue closed because another issue already tracks this problem enhancement

Comments

@FranksRobins
Copy link

FranksRobins commented Mar 30, 2023

Terraform Version

1.1.8

Use Cases

Allow resources to be protected from being destroy while not crashing terraform when using prevent_destroy = true.

This behaviour might be ok when running terraform from the command line but it is not compatible with Consul-Terraform-Sync as the service crashes and is not able to perform any other operation after a service deregisters from Consul and triggers a terraform destroy. Discussions on the subject (for example) come to the conclusion that the user should be running terraform state rm . While this might work when using the command line, it is not suitable when using CTS to manage infrastructure and scripting it would be hackish at best. Neither are scalable and standard to a clean production environment. Also, terraform state rm will sever the binding between Terraform and a resource which is either not always desired, a good idea or even allowed. It would also be preferred not to "orphanate" a resource.

Attempted Solutions

Using prevent_destroy = true which leads to a crash as Terraform exits with an exit code of 1.
terraform state rm might work but cleaning after Terraform is not a solution and will have terraform forget about the resource which does not reflect the need and might even be hazardous.

terraform state rm should be reserved for emergency situations to force forget a resource.

Proposal

Terraform should output that a resource was not destroyed because of the prevent_destroy configuration and continue its course without crashing with an exit code of 1 as not destroying a resource that was configured to not be destroyed is exactly the expected behaviour and not an error.
If other resources are dependent of a specific protected resource then it should also be outputted and Terraform should still be able finish its run with no change to the infrastructure in respect to those resources so using it as a service in the case of CTS prevents a crash and a stall in the infrastructure management.

References

No response

@FranksRobins FranksRobins added enhancement new new issue not yet triaged labels Mar 30, 2023
@jbardin
Copy link
Member

jbardin commented Mar 30, 2023

Duplicate of #16392

@jbardin jbardin marked this as a duplicate of #16392 Mar 30, 2023
@jbardin jbardin closed this as completed Mar 30, 2023
@FranksRobins
Copy link
Author

Duplicate of #16392

More a duplicate of #3874 IMO but thank you for taking the time to reply.

@crw crw added duplicate issue closed because another issue already tracks this problem and removed new new issue not yet triaged labels Mar 31, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate issue closed because another issue already tracks this problem enhancement
Projects
None yet
Development

No branches or pull requests

3 participants