-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
backend (s3/azure): Source config from environment variables #20428
Conversation
@@ -163,8 +163,7 @@ The following configuration options or environment variables are supported: | |||
* `shared_credentials_file` - (Optional) This is the path to the | |||
shared credentials file. If this is not set and a profile is specified, | |||
`~/.aws/credentials` will be used. | |||
* `token` - (Optional) Use this to set an MFA token. It can also be | |||
sourced from the `AWS_SESSION_TOKEN` environment variable. | |||
* `token` / `AWS_SESSION_TOKEN` - (Optional) Use this to set an MFA token. |
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.
Changed the wording of how this is sourced to match the other values in this document.
a7ae7fe
to
a760ebc
Compare
a760ebc
to
db9ee50
Compare
Is it really this simple? I'm not even a Go developer, but I can see what's going on here plain as day. This PR, assuming it works, solves one of the biggest problems I personally have with managing customer's infrastructure using Terraform. I know I'm not the only one, just look at all those linked threads. I can't believe this was all it took. I'm really looking forward to hearing opinions from a Hashicorp person and hoping it gets released fast I've never built Thank you @omar |
Yeah, this wasn't too bad to implement given the Terraform code is well structured. Please do test it 😄! One thing to note, the AWS provider will throw an error if you try to use it with Terraform I know that the Terraform team is gearing up to do a v0.12 release, but I'd be interested if it would be okay to get this in the next v0.11.* release as I'd like to be able to take advantage of this feature without having to switch the CLI to v0.12. |
Any update on this? Would like to know if this is something the team is willing to consider. |
Hi @omar! Sorry for the delay in looking at this. The team at HashiCorp is currently 100% focused on the remaining steps for the Terraform v0.12 release, so we've been unable to give as much attention as we'd like to other things. With that in mind, I've not yet had a chance to look closely at this but I wanted to share some design context for the current implementation of backends that may be helpful: Although it's not directly represented anywhere in the code, conceptually we think of two different categories of inputs to the backends, which answer different questions:
(indeed, for some historical/pragmatic reasons the boundary here is blurry in the sense that some credentials can be provided in configuration, though doing so of course causes Terraform to think of them like location information and force a state migration when they change.) We consider it very important that the location information can change only during Supporting environment variables for these location-related settings would be acceptable only if the environment variables are checked only during We previously implemented the possibility of setting an environment variable called export TF_CLI_ARGS_init='-backend-config="bucket=s3-bucket-name"' The tradeoff there was that we hoped that the environment variable name makes it clear that this variable is only for the |
@apparentlymart, I appreciate the thorough response. I had no idea about the Thanks. I'll close this out. |
I didn't know about |
Very thorough response. Really helped my day. thanks. |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Allows customizing the remote state targets through environment variables.
Solves #17288, #12067, #13022, #12270, and many other requests to interpolate backend configuration. See discussion that prompted this here.
Common usage pattern is to separate Terraform state into S3 bucket/Azure Storage Account for production while all lower environments (dev/QA) can reside in the same location. This gives developers the freedom and sandbox they require to build using Terraform and gives operations folks comfort in separating dev and prod.
Because S3 Buckets and Azure Storage Account must be unique across all AWS/Azure accounts, there will always be name conflicts. Therefore, a different name must be used for the different environments. It's much easier (and better supported) in CI/CD systems to inject the bucket/storage account name via environment variables than in command line switches.
More use cases outlined in the links above prompted me to also include the
key
as an environment variable. For example, the author of #12270 is using a variable inkey
to create a generic backend config for use by other applications that get stored in a centralized S3 bucket per region.