prevent_destroy
A lifecycle setting that makes any plan fail if it would destroy that resource, including as part of a replacement.
In more detail
It suits a few precious resources such as a production database. On most resources it gets in the way, because it also blocks legitimate replacements. It does not stop someone deleting the resource block from the configuration, which removes the setting too.
Example
lifecycle {
prevent_destroy = true
}Related terms
- lifecycle block — A block inside a resource that changes how Terraform replaces or protects it, with settings such as create_before_destroy, prevent_destroy and ignore_changes.
- terraform destroy — The command that deletes every resource the current state records, in reverse dependency order.
- resource replacement — When Terraform must destroy a resource and create a new one because a changed setting cannot be updated in place.
Taught in
- Tearing It Down With Destroy — Infrastructure as Code with Terraform
- Safe Changes With Lifecycle Rules — Infrastructure as Code with Terraform
- Dependencies, depends_on And Lifecycle Rules — HashiCorp Terraform Associate (004) Exam Prep
- Drift: When Reality Stops Matching State — HashiCorp Terraform Associate (004) Exam Prep
- Moved And Removed Blocks: Refactoring Without Rebuilding — HashiCorp Terraform Associate (004) Exam Prep