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

May 23, 2022 | By Gerald | Filed in: Fixes, Terraform Issue.

I was stuck for over an hour debugging the error described below. Despite verifying my AWS credentials locally using the AWS CLI, I was unable to find any issues and the key was still functioning properly upon validation.

The error message is indicating that Terraform is unable to connect to the AWS provider due to missing or incorrect credentials

│ Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│ 
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ 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: i/o timeout
│ 
│ 
│   with module.app_sg.provider["registry.terraform.io/hashicorp/aws"],
│   on .terraform/modules/app_sg/main.tf line 1, in provider "aws":
│    1: provider "aws" {

To resolve this issue, you can try the following:

Step 1. Ensure that the AWS CLI is properly configured on the system where Terraform is being run.

Step 2. Provide explicit AWS credentials to the Terraform AWS provider. This can be done by exporting the AWS access and secret key environment variables in your terminal:

export AWS_ACCESS_KEY_ID="<your-access-key-id>"
export AWS_SECRET_ACCESS_KEY="<your-secret-access-key>"

Step 3. The community recommends that we pin the version described below, as it has been validated and tested by them. Based on this, I also believe that tagging in the version 3.74.2 will provide a solution on my end.

# https://registry.terraform.io/providers/hashicorp/aws/3.74.2
terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "= 3.74.2"
    }
  }
}

If the issue persists, you can refer to the Terraform AWS Provider documentation at https://registry.terraform.io/providers/hashicorp/aws for further information and troubleshooting guidance.

Community issue: https://github.com/hashicorp/terraform-provider-aws/issues/23167

SHARE THIS ARTICLE

Tags: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *