-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform does not read AWS profile from environment variable #233
Comments
I don't understand the "AWS_PROFILE" requirement. Why is this required to work, when it is not required in Packer, for example? Simply defining this in the aws{} block should be sufficient. For example, the following does not work (0.9.6): aws.tf
~/.aws/credentials
~/.aws/config
Then running: What does work? Same config but: So, why does the first fail, while the second work? What is the point of the ENV variable? (also still trying to figure out how region fits into this whole thing, since it seems to be equally arbitrary) |
Finally, why is this whole profiles thing so janky? Like, just make it simple:
and call it a day already :-\ |
Terraform v0.9.8 Im not able to recreate this issue. My config:
It uses the key pair from sub_account profile when I change the profile to |
You shouldn't need to set |
Sorry for the confusion on my end (and the noise). I realized I was missing something crucial. The initial state config and the subsequent terraform run are actually separate credentials. Profiles was working as expected the entire time, but I could not make the initial connection the state bucket with the default profile. |
Same result with:
My environment:
OS = macOS 10.12 |
@seanorama Do you use roles in your profile? you do not need to set any environment variable and works out of the box. Terraform 0.9.11
What works
What DOES NOT work
USING roles in profile?
|
Just putting it here if someone else finds this problem. profile works out of the box if you configured it correctly on awscli on
|
doesnt work for me. just tried on terraform version v0.11.3 and aws cli aws-cli/1.14.10 Ignore. look like i had an issue with my key. recreated and worked fine |
Just in case, check out #1184 as well |
The issue is that I'm already using AWS_PROFILE with Packer and boto3 and it works perfectly. To use Terraform I need to unset AWS_PROFILE AND add a profile in the Terraform provider config. This needs to be fixed ASAP - pick one of the other because this is overcomplicating the whole thing. |
Nope. I just verified against 1.15.0 and got the same exception. The assumed Role has AWSAdmin and boto3 will perform any operations with AWS_PROFILE set:
Here's my Terraform config:
|
So after digging further into #2883 I found that AWS_SDK_LOAD_CONFIG needs to be set for AWS_PROFILE to work. There is no mention of that in this issue OR in the public provider documentation: https://www.terraform.io/docs/providers/aws/index.html. This is an acceptable fix but it needs to be documented. |
@kjenney yeah, that environment variable is poorly documented in all the SDKs. I have had to dig through each one to see if there was support for it. Sorry you didn't know about that, and sorry I didn't think to bring it up sooner :-/ |
Will there be a solution for the aws provider and an s3 backend that uses profiles with assumed roles? Seems like this might be causing some problems and unfortunately it is locked hashicorp/terraform#13589. Setting
Looking for any suggestions? My current solution is statically defining the profile in the provider and the backend, but it has already caused multiple problems :( |
@alock The following configuration works for my team. Our TF code has been converted to a single large module, with instances of this module for each environment. The directory layout is like this:
The
The interesting part is
This config can be used with the
|
as @kjenney said "AWS_SDK_LOAD_CONFIG needs to be set for AWS_PROFILE" |
It seems like we can't reproduce this issue. To help the maintainers find the actionable issues in the tracker, I'm going to close this out, but if anyone is still experiencing this and can either supply a reproduction or logs, feel free to reply below or open a new issue. Thanks! |
@paultyng - Maybe this wasn't meant to be solved with this issue, but I feel like terraform should be able to support environment variables without having to set explicit ~/.aws/config
~/.aws/credentials
main.tf provider "aws" {
region = "us-west-2"
}
terraform {
backend "s3" {
region = "us-west-2"
bucket = "{{S3_BUCKET}}"
key = "{{KEYNAME}}.tfstate"
encrypt = "true"
dynamodb_table = "{{TABLE_NAME}}"
acl = "bucket-owner-full-control"
}
} Failing commands $ AWS_PROFILE={{PROFILE_NAME}} aws iam list-account-aliases
{
"AccountAliases": [
"{{AWS_ALIAS}}"
]
}
$ AWS_PROFILE={{PROFILE_NAME}} AWS_SDK_LOAD_CONFIG=1 terraform init
Initializing the backend...
Error configuring the backend "s3": No valid credential sources found for AWS Provider.
Please see https://terraform.io/docs/providers/aws/index.html for more information on
providing credentials for the AWS Provider
Please update the configuration in your Terraform files to fix this error
then run this command again. |
I've been able to reproduce this locally and have managed to diagnose the issue and worked out why the AWS backend wasn't able to pick up the In short, the reason is that this issue is fixed in this repo but version of this repo that is present in the Terraform repo is an old version before this change was made. @paultyng or someone at HashiCorp - can you update the version of the terraform-provider-aws library in the Terraform repo to fix this? |
Looks like there's already a PR to cover this hashicorp/terraform#17901 |
Upstream PR has been merged and will release with Terraform core 0.11.8. |
For anyone interested, this still hasn't been documented (and I just lost a lot of time because of the elusive AWS_SDK_LOAD_CONFIG), so I've opened a couple of PRs documenting it: |
This appears to be an anti-feature of the AWS Golang SDK which breaks profile support if not set Related: hashicorp/terraform-provider-aws#233
Why is this closed? I have the same issue and nothing works. The configuration is fine with all aws cli, boto3 etc. so there is nothing wrong with .aws credentials. This sholud not be broken Setting the mysterious extra variable somehow to do do with a mumble GO something or other does nothing for me either. This is embarrassing guys. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
This issue was originally opened by @boompig as hashicorp/terraform#8330. It was migrated here as part of the provider split. The original body of the issue is below.
Terraform Version
Terraform v0.7.0
Affected Resource(s)
Probably all of AWS, observed with S3.
Terraform Configuration Files
Debug Output
https://gist.github.com/boompig/f05871140b928ae02b8f835d745158ac
Expected Behavior
Should successfully login then give "noop" text.
Actual Behavior
Does not read the correct profile from environment variable. Works if you provide the profile name in the file, though.
Steps to Reproduce
your_real_profile
terraform apply
The text was updated successfully, but these errors were encountered: