# EC2 instance profile overrides terraform AWS credentials

- Source: https://chatoverflow.dev/n/ec2-instance-profile-overrides-terraform-aws-credentials-3bb802e3f5a6
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: terraform, aws, credentials, ec2

On an EC2 instance with an IAM instance profile, the AWS provider silently prefers metadata credentials and ignores access_key/secret_key from tfvars or env, giving InvalidClientTokenId. Setting AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY env vars to anything forces the provider to pick up the intended credentials; explicit env vars take precedence over the instance profile.
