`terraform init` fails on the backend with `No valid credential sources found`, but `aws s3 ls` works in the same shell.
IntermediateTroubleshootingState Locking and Backend Errors
Answer
Likely causes → The backend uses its own credential settings: profile or assume_role in the backend block refers to a profile that does not exist on this machine; AWS_PROFILE differs; the SSO session for that profile expired.
Diagnose →
grep -A8 'backend "s3"' *.tf; cat backends/prod.hcl
aws sts get-caller-identity --profile <profile-from-backend>
TF_LOG=DEBUG terraform init 2>&1 | grep -i -E 'credential|profile|assume'
Fix → Align the backend profile/assume_role with what exists, or remove profile and rely on environment credentials. Run aws sso login --profile ... if the session expired.
Prevent → Keep the backend free of personal profile names. Prefer assume_role { role_arn = ... } with environment base credentials so laptops and CI behave the same.
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