Terraform: Error: Instance cannot be destroyed — Resource aws_db_instance.prod has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed
The plan would destroy a resource protected with lifecycle { prevent_destroy = true }.
Error: Instance cannot be destroyedResource aws_db_instance.prod has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyedhas lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyedInstance cannot be destroyed Resource has lifecycle.prevent_destroyError: Instance cannot be destroyed on main.tf Meaning
This is a safety guard. Find why the plan wants to destroy/replace it (changed immutable argument, renamed resource, removed block). Fix the change, or temporarily remove prevent_destroy if the destroy is intended. Use moved blocks for renames so state moves without destroying.
Common causes
- Renamed resource/module (new address)
- Changed an argument that forces replacement
- Resource block removed
terraform destroyon protected resources- count/for_each key changes
⚡ Quick fix
- Review the plan; use a
moved { from, to }block for renames - Revert the change forcing replacement
- Remove
prevent_destroyonly if destroy is intended
Detailed fix by platform
Terraform
moved { from = aws_db_instance.db to = aws_db_instance.primary }
How to diagnose
- Reason — Rename or replace?
- Plan — What forces it?
- moved — Used?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- BucketNotEmpty: bucket you tried to delete is not empty Terraform: Error: deleting S3 Bucket (my-bucket): BucketNotEmpty: The bucket you tried to delete is not empty
- DependencyViolation: resource has dependent objects (destroy) Terraform: Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deleted
- Invalid AWS Region Terraform: Error: Invalid AWS Region: us-east-3 / Error: configuring Terraform AWS Provider: validating provider credentials: operation error STS: GetCallerIdentity
Most viewed in Terraform
- Error acquiring the state lock Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked
- Inconsistent dependency lock file Terraform: Error: Inconsistent dependency lock file — provider x: required by this configuration but no version is selected
- Reference to undeclared resource Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026