-
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
[FR] Create Provider Address Environment Variables - Terraform Init #36240
Comments
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again! |
The TFE example was not meant to distract here, rather just the first example that made sense when describing a real world situation. Just to clarify, the change requested here is to Terraform Core, not to any commercial products. |
Hi @straubt1, There are a number of things we're going to have to consider closely here before deciding on an implementation:
|
Terraform Version
Use Cases
Provider Sourcing
For Terraform Enterprise users, sourcing Terraform Providers from private Registries has some challenges that create friction in their journey to governing binaries within their network.
There are two main use cases described here:
Background
When authoring Terraform (*.tf) files a Provider is required to interact with "resources". A Terraform Provider is a binary that is sourced during the
terraform init
command and downloaded from a Registry that implements the Provider Registry Protocol.Terraform Providers are sourced leveraging a "Provider Address" that consists of three different settings in the format "{hostname}/{namespace}/{type}":
When a
resource
block is present, the Provider "type" will be everything to the left of the first underscore ("_").Example using Defaults
The following code would have the Provider "type" of "random":
If there was no other code provided, this provider would be sourced from "registry.terraform.io/hashicorp/random" based on the defaults.
Example using Explicit Sourcing
Terraform provides a mechanism to explicitly set the "Provider Address" (in part or in full) using the
required_providers
block.or
Attempted Solutions
Challenges
When hosting your own private Terraform Providers (developed within a company and not publicly available), or pulling public Terraform Providers into an airgapped TFE installation (a private network without egress to reach "registry.terraform.io"), the
required_providers
block is required within your Terraform code.If we build on top of the example above, let's consider some Terraform Code that references several other Terraform Modules.
I have to provide explicit sourcing for my Provider:
This code has to be at the root module level, but it also must be present in every Terraform Module that it consumes!
Unfortunately this results in a lot of code maintenance that could be otherwise avoided.
Proposal
Recommended Solution
The goal here is to allow changing the behavior of Terraform Provider sourcing during a
terraform init
without requiring an update to the Terraform Code itself.In each of the recommendation let's assume that the following code is present:
The local module (which could be remote as well) at "./modules/server_farm" has a similar provider reference.
Implement New Environment Variables
Create a new configuration options that are settable via an Environment Variables that are used during
terraform init
when nosource
attribute is set in anyrequired_providers
block.The proposed settings are:
Effectively this would not change any current behavior when these Environment Variables are not set. It would however give great flexibility to those who who are either moving or will move how Terraform Providers are sourced within their environments.
Other Considerations
Terraform CLI Configuration File
There may be a desire to allow this configuration using the Terraform CLI Configuration File, which would be a great idea as long as these settings are available as Environment Variables.
In TFE or HCP Terraform, it is difficult to modify this CLI configuration since the platform creates it's own during a Terraform Run. Currently the only way to update this CLI configuration is with a custom Terraform Agent. Therefore it is critical that if these settings are to be implemented, that they be set with Environment Variables.
Lock File
With this change, the
.terraform.lock.hcl
file would maintain the actual Registry that was sourced duringterraform init
since the "Provider Address" is present in that lock file.Example:
References
No response
The text was updated successfully, but these errors were encountered: