Interview Prep/Terraform/Authentication and Cloud API Errors

GitHub Actions: `Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity`.

IntermediateTroubleshootingAuthentication and Cloud API Errors
Answer

Likely causes → The trust policy's token.actions.githubusercontent.com:sub condition doesn't match (different repo, branch, environment or PR context); wrong aud; the OIDC provider isn't created in that account.

Diagnose → Common sub values: repo:acme/infra:ref:refs/heads/main, repo:acme/infra:environment:prod, repo:acme/infra:pull_request. Compare with the trust policy.

Fix →

"Condition": {
  "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" },
  "StringLike":   { "token.actions.githubusercontent.com:sub": "repo:acme/infra:environment:prod" }
}

Prevent → Separate roles for plan (PRs, read-only) and apply (protected environment only).

All Terraform questions

More on Authentication and Cloud API Errors