HCP Terraform: `terraform plan` from a laptop says `Error: Required token could not be found` for `app.terraform.io`.
BeginnerTroubleshootingState Locking and Backend Errors
Answer
Likely causes → The cloud {} block (or remote backend) needs an API token; you haven't logged in, or the token in ~/.terraform.d/credentials.tfrc.json expired or was revoked.
Diagnose → cat ~/.terraform.d/credentials.tfrc.json | jq 'keys'; check TF_TOKEN_app_terraform_io in CI.
Fix → terraform login on a laptop. In CI set TF_TOKEN_app_terraform_io to a team or user token from a secret.
Prevent → Use team tokens for automation with an expiry, rotated through your secret manager.
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` 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