Bobcares

Terraform AWS Provider Error – Failed to get shared config profile

Learn how to fix the Terraform AWS provider error-  failed to get shared config profile. Our AWS Support team is here to answer queries and concerns.

How to Fix “Failed to Get Shared Config Profile” Error in Terraform with AWS

How to Fix “Failed to Get Shared Config Profile” Error in Terraform with AWSIf you have run into the error “Failed to get shared config profile” when working with Terraform and AWS, our Experts are here to help.

This error usually means Terraform can’t find or access the AWS profile we specified, either through environment variables or in the configuration files.

This error typically occurs due to issues with the configuration of AWS credentials or profiles. Here’s how to resolve it:

First, ensure the `AWS_PROFILE` environment variable is set to a valid profile name that exists in the `~/.aws/credentials` or `~/.aws/config` file.

For example:

export AWS_PROFILE=default

In this case, it was set to `terracase`, but my credentials file didn’t have a profile with that name. Switching to a valid profile fixed the error.

Understanding the Credential Lookup Order

Terraform follows a specific order of precedence:

  1. `provider.profile` in `main.tf`
  2. `AWS_PROFILE` environment variable
  3. Default profile in `~/.aws/credentials`

If no default profile exists, we have to reference the profile name.

Here is an example profile:


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

So, to use this, export the profile:

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

Or set it directly in `main.tf`:


provider "aws" {
region = "us-west-2"
profile = "https://sso.jumpcloud.com/saml2/aws"
}

Terraform AWS Provider V4 Changes

A key change in the AWS Provider v4 is that it fails if the specified profile doesn’t exist, unlike v3, which would fall back. This breaking change has tripped up many users, as also seen with other errors like AWS: Too Few Arguments.

So, to handle this in CI/CD pipelines, we can create a variable to toggle between local and pipeline credentials:


provider "aws" {
region = "us-west-2"
profile = var.pipeline ? "" : "my-local-profile"
}

Then set the `pipeline` variable to `true` in the pipeline environment, allowing Terraform to use default credentials or environment variables in CI, while keeping local profile support.

By properly managing the AWS credentials:

  • Local and CI/CD environments work seamlessly.
  • Also, errors related to profile access are eliminated.
  • We avoid breaking changes from Terraform provider upgrades.

Common Fixes Recommended by Our Experts

  • Remove quotes in profile names. This is valid for AWS CLI but not for Terraform:

    [profile "project1-admin"] # Incorrect for Terraform
    [project1-admin] # Correct
  • Or, set `shared_credentials_file` directly in the provider block:

    provider "aws" {
    region = "us-east-1"
    shared_credentials_files = ["C:/Users/johnny/.aws/credentials"]
    profile = "johnny"
    }

If you’re managing file transfers to AWS EC2, we also recommend reading how to access an AWS server using FileZilla for quick SFTP setup tips.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to fix the Terraform AWS provider error- failed to get shared config profile.

0 Comments

Submit a Comment

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

server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF