Interview Prep/Terraform/State Locking and Backend Errors

`terraform init` fails with `Error: Variables not allowed` pointing at the `backend "s3"` block.

BeginnerTroubleshootingState Locking and Backend Errors
Answer

Likely causes → You wrote bucket = var.state_bucket or key = "${var.env}/terraform.tfstate". The backend is initialized before variables are evaluated, so no variables, locals or functions are allowed there.

Diagnose → Read the line number in the error; it points into the terraform { backend ... } block.

Fix → Use partial configuration:

terraform {
  backend "s3" {}
}
terraform init -backend-config=backends/prod.hcl

Prevent → Keep a backends/<env>.hcl per environment, or let Terragrunt generate the backend block.

All Terraform questions Roadmap: Terraform in production

More on State Locking and Backend Errors