`terraform init` fails with `Error: Backend configuration changed`.
BeginnerTroubleshootingState Locking and Backend Errors
Answer
Likely causes → You edited the backend block (bucket, key, region, role) or passed different -backend-config values than the ones cached in .terraform/terraform.tfstate.
Diagnose →
cat .terraform/terraform.tfstate | jq '.backend.config | {bucket,key,region}'
Compare with the backend block and your -backend-config file.
Fix →
- You want to move state to the new location:
terraform init -migrate-state. - The state is already at the new location, or you only switched env config locally:
terraform init -reconfigure.
Prevent → In CI, always run terraform init -reconfigure -backend-config=env/prod.hcl in a clean workspace so no stale .terraform is reused.
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`.BeginnerA teammate ran `terraform apply -lock=false` "because the lock was stuck". Now the plan shows resources you never touched being recreated.Advanced`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