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