Interview Prep/Terraform/State Locking and Backend Errors

In CI, `terraform init` hangs forever after printing `key The path to the state file inside the bucket Enter a value:`.

IntermediateTroubleshootingState Locking and Backend Errors
Answer

Likely causes → Partial backend config with a required setting missing (the -backend-config file path is wrong, or the file lacks key). Terraform falls back to an interactive prompt.

Diagnose → Check the job's working directory and that the backend file exists: ls backends/ && cat backends/prod.hcl.

Fix → Pass the correct file and disable prompts:

terraform init -input=false -backend-config=backends/prod.hcl

Prevent → Always use -input=false in automation and set TF_IN_AUTOMATION=1. A missing value then fails fast instead of hanging until the job timeout.

All Terraform questions Roadmap: Terraform in production

More on State Locking and Backend Errors