Error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found

I use terrafrom to build aws resource and it work fined before,but today I suddenly got a error “error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.” when run the terraform plan commend, and the full error is ╷
│ Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.

│ Please see Terraform Registry
│ for more information about providing credentials.

│ Error: no EC2 IMDS role found, operation error ec2imds: GetMetadata, request send failed, Get “http://169.254.169.254/latest/meta-data/iam/security-credentials/”: dial tcp 169.254.169.254:80: connectex: A socket operation was attem
pted to an unreachable network.


│ with provider[“Terraform Registry”],
│ on main.tf line 5, in provider “aws”:
│ 5: provider “aws” {


my provider config is:
terraform {
required_version = “>=0.12”
}

provider “aws” {
profile = var.profile
shared_credentials_files = ["~/.aws/credentials"]
region = var.region
allowed_account_ids = [var.accountId]
}

looks like it can’t find the profile in shared_credentials_files,could someone please help me out?

I’m having the exact same issue. Earlier terraform plan used to work fine, looks like this has something to do with new aws provider version 4.1
Did you manage to find the resolution ?

According to what you said, after I downgraded the aws provider version to 3.7.1, the error is gone

I had the exact same issue. After I downgraded the aws provider version to 3.74.2, the error is gone.

hmm interesting. hopefully hashicorp provides input. We need a solution that works with 4.2.0

1 Like

There is a good write up about what needs to be changed to resolve this here:

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#changes-to-authentication

I faced the same error while launching my first instance on aws, I just added access_key and secret_key in the provider section and my error solved after terraform plan.
provider “aws” {
region = “us-east-2”
#new line added here
access_key = “######”
secret_key = “######”

}

3 Likes

this worked for me. Make sure the syntax is just as she put it above. Thanks again @zebakhann

@zebakhann which acces and secret key are we talking about? i am facing the same issue as the others…

@zebakhann i actually generated both keys on my aws ec2 instance but the issue is still not resolved…

What is the exact error that you’re getting?
Please post your provider configuration as well.

It is working now. I had to save all the terraform files after the changes i applied and some other small details. Thanks anyways!

I had same issue and your solution works for me.

This helped for me as well

Thanks