Interview Prep/Terraform/State Locking and Backend Errors

`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.

All Terraform questions Roadmap: Terraform in production

More on State Locking and Backend Errors