A teammate ran `terraform apply -lock=false` "because the lock was stuck". Now the plan shows resources you never touched being recreated.
AdvancedTroubleshootingState Locking and Backend Errors
Answer
Likely causes → Two applies wrote state concurrently. The last writer won, so the state no longer records objects the other run created. Terraform now plans to create (duplicate) or destroy things based on an incomplete state.
Diagnose →
aws s3api list-object-versions --bucket acme-tfstate --prefix prod/app/terraform.tfstate \
--query 'Versions[].{v:VersionId,t:LastModified,size:Size}'
terraform state list | sort > now.txt
Download the previous versions and diff terraform state list output between them.
Fix → Freeze applies. Either restore the most complete state version and terraform import what the other run created, or keep the current one and import the missing objects. Re-plan until it shows only intended changes.
Prevent → Remove the habit: block -lock=false in CI wrappers, and teach force-unlock with verification instead.
More on State Locking and Backend Errors
`terraform plan` fails with `Error acquiring the state lock` and `ConditionalCheckFailedException: The conditional request failed`.BeginnerWith the S3 backend and `use_lockfile = true`, you get `Error acquiring the state lock` with `StatusCode: 412` and `PreconditionFailed`.Intermediate`terraform force-unlock` returns `Failed to unlock state: lock ID "..." does not match existing lock`.Beginner`terraform init` fails with `Error: Backend configuration changed`.Beginner`terraform init -migrate-state` asks `Do you want to copy existing state to the new backend?` and the new backend already has a state. What is the danger?Intermediate`Error: Backend initialization required, please run "terraform init"` with `Reason: Initial configuration of the requested backend "s3"`.Beginner