Instance cannot be destroyed (lifecycle.prevent_destroy) Terraform Origin: Platform & cloud OSI layer 7 · Application Last updated 5 Nov 2026

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 }.

Exact message you may see 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
Seen on: Terraform

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 destroy on protected resources
  • count/for_each key changes

⚡ Quick fix

  1. Review the plan; use a moved { from, to } block for renames
  2. Revert the change forcing replacement
  3. Remove prevent_destroy only if destroy is intended

Detailed fix by platform

Terraform

  1. moved { from = aws_db_instance.db to = aws_db_instance.primary }

How to diagnose

  1. Reason — Rename or replace?
  2. Plan — What forces it?
  3. 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:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

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 (Terraform)BucketNotEmpty: bucke…DependencyViolation: resource has dependent objects (destroy) — Terraform: Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deleted (Terraform)DependencyViolation: …Invalid AWS Region — Terraform: Error: Invalid AWS Region: us-east-3 / Error: configuring Terraform AWS Provider: validating provider credentials: operation error STS: GetCallerIdentity (Terraform)Invalid AWS RegionMoved object still exists — Terraform: Error: Moved object still exists — This statement declares a move from aws_x.old, but that resource instance is still declared at main.tf (Terraform)Moved object still ex…No valid credential sources found (AWS provider) — Terraform: Error: No valid credential sources found — failed to refresh cached credentials, no EC2 IMDS role found / Error: configuring Terraform AWS Provider: no valid credential sources (Terraform)No valid credential s…Provider configuration not present (removed resource) — Terraform: Error: Provider configuration not present — its original provider configuration is required, but it has been removed (Terraform)Provider configuratio…Resource is tainted and must be replaced — Terraform: # aws_instance.web is tainted, so must be replaced — -/+ destroy and then create replacement (Terraform)Resource is tainted a…UnauthorizedOperation / AccessDenied during Terraform apply — Terraform: Error: creating EC2 Instance: UnauthorizedOperation: You are not authorized to perform this operation. User: arn:aws:iam::123:user/ci is not authorized to perform: ec2:RunInstances (Terraform)UnauthorizedOperation…Instance …

Explore the map of this error Full error map →

🧠 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.