Interview Prep/Terraform/Lost, Corrupted and Drifted State

`terraform plan -refresh-only` shows drift, and you apply it. The next normal plan still wants to revert the change. Why?

IntermediateTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → apply -refresh-only updates state to match reality but doesn't change code. The code still says the old value, so the next plan reverts.

Diagnose → Compare the value in code with terraform state show <addr>.

Fix → Update the code to the new value (or add ignore_changes), then plan should be clean.

Prevent → Use refresh-only only to record accepted drift, and always follow up with a code change in the same PR.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State