Interview Prep/Terraform/Lost, Corrupted and Drifted State

A resource was deleted manually in the console. The plan wants to create it, and an apply fails because a dependent resource still references the old ID.

IntermediateTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → Refresh noticed the object is gone and planned a create, but dependents (route table association, target group attachment) were not updated in the same plan because their attributes didn't appear to change.

Diagnose → terraform plan shows + create for the deleted resource, and dependents show no change or known after apply IDs.

Fix → Usually one apply resolves it; if dependents still point at the old ID, force them to be recreated:

terraform apply -replace='aws_route_table_association.private["a"]'

Prevent → Restrict delete permissions in prod; use prevent_destroy on critical resources so even Terraform won't remove them without a code change.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State