terraform
lifecycle_error
ai_generated
true
Error: Instance cannot be destroyed: resource has lifecycle.prevent_destroy set
ID: terraform/tf-lifecycle-prevent-destroy
90%Fix Rate
92%Confidence
70Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Terraform plan includes destroying a resource that has prevent_destroy lifecycle rule enabled.
genericWorkarounds
-
92% success Remove or set prevent_destroy = false before destroying
Update the lifecycle block: lifecycle { prevent_destroy = false }, then run terraform apply, then destroySources: https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle
-
85% success Use terraform state rm to remove from state without destroying the actual resource
terraform state rm RESOURCE_ADDRESS removes the resource from Terraform management without destroying it in the cloud
Sources: https://developer.hashicorp.com/terraform/cli/commands/state/rm
Dead Ends
Common approaches that don't work:
-
Use terraform destroy -target to bypass prevent_destroy
90% fail
The -target flag does not override lifecycle rules; prevent_destroy still blocks the destroy
-
Modify the state file directly to remove the resource
75% fail
Direct state modification is error-prone and the resource still exists in the cloud, creating drift
Error Chain
Preceded by:
Frequently confused with: