Interview Prep/Terraform/Lost, Corrupted and Drifted State

`terraform show` displays a resource with `status: tainted` and the plan says `is tainted, so must be replaced`. Nobody ran `terraform taint`.

BeginnerTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → A previous apply created the resource but a later step on it failed (provisioner error, health wait timeout). Terraform marks it tainted because it may be half-configured.

Diagnose → Check the earlier apply log for the failure on that resource; check the real object's health.

Fix → If the object is actually fine, terraform untaint aws_instance.web. Otherwise let the plan replace it.

Prevent → Avoid provisioners; use user_data/cloud-init or configuration management. Set realistic timeouts {} for slow resources.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State