Interview Prep/Terraform/State Locking and Backend Errors

`Error: Error acquiring the state lock` with `AccessDeniedException: User: arn:aws:sts::...:assumed-role/tf-ci/... is not authorized to perform: dynamodb:PutItem`.

BeginnerTroubleshootingState Locking and Backend Errors
Answer

Likely causes → The role has S3 access but no DynamoDB permissions on the lock table, or the table is in another region/account.

Diagnose → aws dynamodb describe-table --table-name terraform-locks --region <backend-region>

Fix → Grant dynamodb:GetItem, dynamodb:PutItem, dynamodb:DeleteItem (and DescribeTable) on the table ARN. Or switch to use_lockfile = true and drop DynamoDB.

Prevent → Ship backend permissions as one reusable IAM policy so S3, KMS and locking are granted together.

All Terraform questions Roadmap: Terraform in production

More on State Locking and Backend Errors