Interview Prep/Terraform/Authentication and Cloud API Errors

Terraform deploys to the wrong account: resources appear in the sandbox account although you targeted prod.

AdvancedTroubleshootingAuthentication and Cloud API Errors
Answer

Likely causes → AWS_PROFILE/env credentials override what you expected; assume_role missing in the provider; static keys from a previous job lingering on a self-hosted runner.

Diagnose → aws sts get-caller-identity; terraform state show an affected resource to see the ARN's account ID.

Fix → Destroy the misplaced resources (or state rm and clean up manually), then fix credentials and apply to prod.

Prevent → Add allowed_account_ids to the provider; Terraform refuses to run against any other account:

provider "aws" {
  region              = "ap-south-1"
  allowed_account_ids = ["222222222222"]
}
All Terraform questions

More on Authentication and Cloud API Errors