# 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

**Code:** `Instance cannot be destroyed (lifecycle.prevent_destroy)` · **Category:** Terraform · **Seen on:** Terraform

The plan would destroy a resource protected with `lifecycle { prevent_destroy = true }`.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/terraform/prevent-destroy-lifecycle)
