-
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
Document AWS_SDK_LOAD_CONFIG on aws provider #8451
Conversation
I left a comment about this over in hashicorp/terraform#21122 but want to note it over here for better visibility: If this environment variable is not normally required by other AWS-integrated tools like the AWS CLI then I think the ideal path here would be to find a way to make Terraform's AWS provider and S3 backend not require it either, since I think our goal is that any user with a properly-configured and functioning AWS CLI should be able to run Terraform without any special further configuration to get their credentials to apply. I don't know if that ideal can actually be achieved within the limitations of the SDK, but perhaps we should investigate that further (if we didn't already) and consider documenting this additional awkward extra step as a last resort? |
Alright, thanks @apparentlymart ! I answered at hashicorp/terraform#21122 but I'm mostly copying the answer here, since it's relevant to both scenarios: According to the aws golang sdk docs, it seems one should be able to override this using NewSessionWithOptions:
The aws terraform provider uses hashicorp/aws-sdk-go-base. It actually defines the However, it does so only if Config.Profile is set (https://github.com/hashicorp/aws-sdk-go-base/blob/master/session.go#L42). When setting AWS_PROFILE from the environment variable, Config.Profile is not set, and this setting is ignored. So a possible fix is to configure the CLI to set Config.Profile when AWS_PROFILE is set:
To:
Maybe support AWS_DEFAULT_PROFILE as well, but I think it's deprecated. Anyway, I would've proposed this change from the beginning but I worried this'd need a fair bit of testing, and may need to wait for the next major version release since this might be considered a breaking change (there might be some terraform scripts out there running in an environment with AWS_PROFILE set, but AWS_SDK_LOAD_CONFIG unset, so they're actually using - knowingly or not - the default |
@@ -101,6 +101,9 @@ provider "aws" { | |||
} | |||
``` | |||
|
|||
If specifying the profile through the `AWS_PROFILE` environment variable, you | |||
must also set `AWS_SDK_LOAD_CONFIG` to a truthy value, e.g. `AWS_SDK_LOAD_CONFIG=1` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording of "must" here is overly strong, since AWS_PROFILE
can successfully be used today in situations without AWS_SDK_LOAD_CONFIG
. For example, the usage of only the AWS_PROFILE
environment variable, works when the credentials are in a credentials file and the profile does not have any advanced configurations, such as: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
See also: #8779 (comment)
My recommendation would be to call out specific usages that require the additional environment variable, e.g.
must also set `AWS_SDK_LOAD_CONFIG` to a truthy value, e.g. `AWS_SDK_LOAD_CONFIG=1` | |
may also need to set `AWS_SDK_LOAD_CONFIG` to a truthy value (e.g. `AWS_SDK_LOAD_CONFIG=1`) for advanced AWS client configurations, such as profiles that use the `source_profile` or `role_arn` configurations. |
Merged with suggestion above. 👍 |
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! |
Community Note
Changes proposed in this pull request:
Fixes:
There are multiple (closed) issues about this with calls for documentation, such as:
Closes AWS_PROVIDER not working, explicit 'provider=xx' works fine #8779
I've run some tests and confirmed that this is an issue both when configuring the S3 backend and when configuring the AWS provider (see other PR hashicorp/terraform#21122). I can detail the results if required, but given the number of existing issues and the aws-sdk-go documentation I think this behavior is as "confirmed" as it gets.
Notes:
AWS_SDK_LOAD_CONFIG is a configuration specific to AWS Golang SDK (and JavaScript SDK as well -- and no other SDK, as far as I can tell).
Per the AWS documentation, this must be set when using the Go SDK, otherwise AWS_PROFILE is ignored:
This variable is not particularly well documented and seems to be a source of confusion, being limited to only two SDKs (Boto does not have it and profiles work on the fly). Personally if there's approval from the maintainers I'd edit the code to act as if AWS_SDK_LOAD_CONFIG is set true, but documenting seems to be the next best thing.