Interview Prep/Terraform/Authentication and Cloud API Errors

`Error: Cannot assume IAM Role` — `api error AccessDenied: User: arn:aws:iam::111111111111:user/ci is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::222222222222:role/terraform`.

IntermediateTroubleshootingAuthentication and Cloud API Errors
Answer

Likely causes → The target role's trust policy doesn't trust the caller, the caller's identity policy lacks sts:AssumeRole on that ARN, a required ExternalId is missing, or an SCP denies it.

Diagnose →

aws iam get-role --role-name terraform --query 'Role.AssumeRolePolicyDocument'   # run in account 222
aws sts assume-role --role-arn arn:aws:iam::222222222222:role/terraform --role-session-name test

Fix → Add the caller as Principal in the trust policy and sts:AssumeRole in the caller's policy; pass external_id in assume_role {} if the trust policy requires it.

Prevent → Manage trust relationships in Terraform in a central IAM stack, tested by a pipeline smoke test.

All Terraform questions

More on Authentication and Cloud API Errors