How to fix-error configuring S3 Backend no valid credential sources for S3 Backend found?


I had an issue while I was trying to setup Remote S3 bucket for storing Terraform state file. The issue faced is error configuring S3 Backend no valid credential sources for S3 Backend found.

After spending some time on my local terraform setup and AWS CLI configuration I realised that my AWS CLI was using incorrect Access Key and Secret Key with my AWS CLI.

Here is the screenshot of the error when I issued terraform init -

error configuring S3 Backend no valid credential sources for S3 Backend found

How to fix the Error?

1. Reconfigure the AWS CLI with correct Access Key and Secret Key

The most probably cause of this issue is you are using incorrect Access Key and Secret Key with your AWS CLI.

You must set the correct values using the command aws configure

Here is an example -

1$ aws configure
2AWS Access Key ID [None]: <Enter your Correct Access Key ID>
3AWS Secret Access Key [None]:<Enter your Correct Secret Access Key >
4Default region name [None]: <Set the correct Region>
5Default output format [None]: json

Why AWS CLI?- [Terraform][3] in the background uses AWS CLI to communicate with the AWS S3 Bucket, so if your AWS CLI is using expired or incorrect Access Key, Secret Access Key then terraform init command will throw this error.


2. Set the correct AWS Access Key, Secret Access Key and Region Name in the Terraform Manifest

The second most probably cause for this issue is your Terraform Manifest is using the wrong AWS Access Key, Secret Access Key and Region Name. Check your Terraform file and look for the AWS Access Key, Secret Access Key if your Access key and Secret Access key is incorrect then replace it with correct AWS Access Key, Secret Access Key.

Here is a sample code snippet which you can also find inside terraform configuration file -

1provider "aws" {
2   region     = "<enter-your-region-id>"
3   access_key = "<enter-your-correct-access-key>"
4   secret_key = "<enter-your-correct-secret-key>"
5} 

3. Run terraform init with -backend-config

The third option would be to run terraform init command with -backend-config using correct AWS Access Key, Secret Access Key.

Here is an example -

1terraform init -backend-config="access_key=<your access key>" -backend-config="secret_key=<your secret key>" 
2-backend-config="region=<your region>" 

Read More -

  1. Install terraform on Ubuntu 20.04, CentOS 8, MacOS, Windows 10, Fedora 33, Red hat 8 and Solaris 11
  2. How to setup Virtual machine on Google Cloud Platform using terraform
  3. Create EC2 Instance on AWS using terraform
  4. How to use Terraform Input Variables
  5. What is variable.tf and terraform.tfvars?
  6. How to use Terraform locals?
  7. How to use Terraform output values?
  8. Understanding terraform count, for_each and for loop?
  9. Cloud-nuke : How to nuke AWS resources and save additional AWS infrastructure cost?
  10. How to use Terraform Dynamic blocks?
  11. How to use Terraform resource meta arguments?
  12. How to use Terraform Data sources?
  13. What is terraform provisioner?
  14. Terraform how to do SSH in AWS EC2 instance?
  15. How Terraform modules works?
  16. How to run specific terraform resource?
  17. How to use Workspaces in Terraform?
  18. Securing AWS secrets using HashiCorp Vault with Terraform?
  19. Managing Terraform states?
  20. Terraform state locking using DynamoDB (aws_dynamodb_table)
  21. Terraform and AWS credentials handling?
  22. Terraform and AWS Multi account Setup?