skip to Main Content

In my main.tf file I have:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.16"
    }
  }

  required_version = ">= 1.2.0"
}

provider "aws" {
  region = "us-west-2"
}

When I run terraform plan, I am getting the error below:

Error: configuring Terraform AWS Provider: failed to get shared config profile, terragrunt
 
   with provider["registry.terraform.io/hashicorp/aws"],
   on provider.tf line 2, in provider "aws":
    2: provider "aws" {

In my case, I’m not using terragrunt in the project at all, purely terraform and the error message isn’t helpful.

2

Answers


  1. Chosen as BEST ANSWER

    Solution:

    My AWS_PROFILE env variable was set to terragrunt. And because my ~/.aws/credentials file didn't have a profile for terragrunt, I was getting the error. I had to set it to an existing profile and my problem was fixed.

    Context:

    The shared config profile terraform is talking about has to do with the provider.profile variable in main.tf, AWS_PROFILE environment variable, and the ~/.aws/credentials file. In that order of prescedence.

    If your ~/.aws/credentials doesn't have a default profile, then you must point to it explicitly. For example, if it looks like below:

    [https://sso.jumpcloud.com/saml2/aws]
    aws_access_key_id        = <example-id>
    aws_secret_access_key    = <example-key>
    

    Then you have to either

    1. run export AWS_PROFILE=https://sso.jumpcloud.com/saml2/aws

    or

    1. manually specify the profile in your main.tf
    provider "aws" {
      region = "us-west-2"
      profile = "https://sso.jumpcloud.com/saml2/aws"
    }
    

  2. This worked for me on Windows:

    provider "aws" {
       region                  = "us-east-1"
       shared_credentials_files  = ["C:/Users/johnny/.aws/credentials"]
       profile                 = "johnny" 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search