Interview Prep/Terraform/Lost, Corrupted and Drifted State

`terraform state list` shows `aws_instance.web` but the plan says `aws_instance.web will be destroyed` with `(because aws_instance.web is not in configuration)`.

BeginnerTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → The block was deleted or renamed in code, or it lives in a file that isn't in this directory (moved to a module, or a file renamed to .tf.bak).

Diagnose → grep -rn 'resource "aws_instance" "web"' .

Fix → If renamed or moved into a module, add a moved block. If intentionally removed from management without destroying it, use a removed block with lifecycle { destroy = false }. If it should be destroyed, apply.

Prevent → Treat any unexpected destroy in plan as a blocker in review; add a CI check that fails on destroys unless a label is set.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State