Table of Contents
The Error
Error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found
What Causes This
The AWS provider exhausted its entire credential chain without finding valid credentials. Terraform checks in order: environment variables, shared credentials file (~/.aws/credentials), shared config (~/.aws/config), EC2 instance profile/ECS task role. If none provide valid credentials, you get this error.
How to Fix It
Solution 1: Set Environment Variables
export AWS_ACCESS_KEY_ID="AKIA..."
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_REGION="us-east-1"
# For temporary credentials (STS)
export AWS_SESSION_TOKEN="your-session-token"
terraform plan
Solution 2: Configure Shared Credentials
# Create or update ~/.aws/credentials
aws configure
# Or manually:
mkdir -p ~/.aws
cat > ~/.aws/credentials << CREDS
[default]
aws_access_key_id = AKIA...
aws_secret_access_key = your-secret-key
CREDS
Solution 3: Use Named Profiles
provider "aws" {
region = "us-east-1"
profile = "production" # Uses [production] from ~/.aws/credentials
}
Solution 4: EC2 Instance Profile
# Verify instance has an IAM role attached
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/
# Should return the role name
# If no role, attach one via AWS Console or CLI
aws ec2 associate-iam-instance-profile \
--instance-id i-0123456789abcdef0 \
--iam-instance-profile Name=my-instance-profile
Solution 5: ECS Task Role
resource "aws_ecs_task_definition" "app" {
family = "my-app"
task_role_arn = aws_iam_role.task.arn
execution_role_arn = aws_iam_role.execution.arn
# ...
}
Solution 6: Debug the Credential Chain
# See which credentials Terraform finds
export TF_LOG=DEBUG
terraform plan 2>&1 | grep -i "credential\|auth\|assume"
Prevention Tips
- Pin provider versions — avoid surprise breaking changes
- Use CI/CD — catch errors before they hit production
- Test with
terraform plan— always review before applying - Keep Terraform updated — newer versions have better error messages
- Use
terraform validate— catches syntax errors early
Hands-On Courses
Learn to avoid these errors with interactive, project-based courses:
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
- Terraform Cheat Sheet — quick reference for all commands
Related Articles
- Terraform Troubleshooting - Common Errors and Solutions
- Terraform Enabling and Using Debugging
- Fix Terraform Error - No Valid Credential Sources Found
Conclusion
This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

