-
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
[feature request] Allow dynamic provider aliases inside resources #3656
Comments
This overlaps a bit with the more theoretical discussion in #1819. |
There is some overlap but this request is more about using the aliased providers, not with creating the aliased providers. (Though I like the ideas so far with #1819 ) |
other related issues
|
This will be very useful indeed. |
is this issue fixed by #16379 ? |
I suppose this is the first feature that I am looking for on every terraform release CHANGELOG. Since 2015, there is still no solution. :( |
Hitting this brick wall in 2020 |
also waiting for it. |
Is there some work around that the 52 of us who plus one'd 👍 this issue are missing? |
Here is how I would do the thing in the original comment here using current Terraform language features: variable "hosting" {
type = string
}
locals {
openstack_settings = tomap({
internal = {
tenant_name = "dev"
auth_url = "http://myauthurl.dev:5000/v2.0"
}
rackspace = {
tenant_name = "my-tenant"
auth_url = "http://rackspace:5000/v2.0"
}
hpcloud = {
tenant_name = "my-tenant"
auth_url = "http://hpcloud:5000/v2.0"
}
})
}
provider "openstack" {
tenant_name = local.openstack_settings[var.hosting].tenant_name
auth_url = local.openstack_settings[var.hosting].auth_url
}
resource "openstack_compute_instance_v2" "server" {
} |
@apparentlymart, that workaround doesn't work with my use case. I create multiple azure_kubernetes_cluster instances using for_each, then wish to use multiple kubernetes providers instantiated using certificates from the AKS instances to apply resources inside the clusters. A provider supporting for_each and a dynamic alias would do the trick. If module supported for_each, I could create a workaround that way too. Alas, Terraform supports neither solution as of version 0.12.24. |
The key design question that needs to be answered to enable any sort of dynamic use of provider configurations (whether it be via Using the most recent comment's use-case as an example, I think you're imaging something like this: # This is a hypothetical example. It will not work in current versions of Terraform.
variable "clusters" {
type = map(object({
# (some suitable cluster arguments)
})
}
resource "azure_kubernetes_cluster" "example" {
for_each = var.clusters
# (arguments using each.value)
}
provider "kubernetes" {
for_each = azure_kubernetes_cluster.example
# (arguments using each.value from the cluster objects)
}
resource "kubernetes_pod" "example" {
for_each = azure_kubernetes_cluster.example
provider = provider.kubernetes[each.key]
# ...
} The above presents to significant challenges:
Both of these things seem solvable in principle, which is why this issue remains open rather than being closed as technically impossible, but at the same time they both involve some quite fundamental changes to how providers work in Terraform that will inevitably affect the behavior of other subsystems. This issue remains unsolved not because the use-cases are not understood, but rather because there is no technical design for solving it that has enough detail to understand the full scope of changes required to meet those use-cases. The Terraform team can only work on a limited number of large initiatives at a time. I'm sorry that other things have been prioritized over this, but I do stand behind the prioritization decisions that our team has made. In the meantime, I hope the example above helps some of you who have problems like the one described in the opening comment of this issue where it is the configuration itself that is dynamic, rather than the number of configurations. For those who have more complex systems where the number of provider configurations is what is dynamic, my suggested workaround would be to split your configuration into two parts. Again using the previous comment as an example:
The workflow for adding a new cluster would then be:
The workflow to remove an existing cluster would be:
I'm not suggesting this with the implication that it is an ideal or convenient solution, but rather as a potential path for those who have a similar problem today and are looking for a pragmatic way to solve it with Terraform's current featureset. |
Thanks, @apparentlymart, for that very clear and detailed explanation. You've hit on exactly the config that I was trying to use. I haven't played with workspaces yet, but the workaround that I had already settled on was moving the kubernetes provider and its dependencies into a child module. This gives me some module invocations that I need to keep in sync with
Looking at this again, I could have just moved everything into the child module, gotten rid of
Anyhow, given those factors, it seems to me that allowing providers to use loops and resources to use dynamically named providers shouldn't introduce any more problems than already exist in my multiple module invocation scenario. Maybe I'm missing some edge cases but, again, I think I can duplicate any such cases by invoking modules multiple times with the existing feature set. |
I'm not sure I fully followed what you've been trying @derekrprice, but if you have a
The addressing syntax will be different in your scenario -- You aren't needing to use I'm currently focused on an entirely separate project so I can't go any deeper on design discussion for this right now. My intent here was just to answer the earlier question about whether there were any known workarounds; I hope the two workarounds I've offered here will be useful for at least some of you. |
Could this make it into v0.14? |
Late in the race but would like to see some solution soon for this issue......repeated code for multiple subscriptions to perform the same operation is a pain |
go on, this would would in pulumi easy! |
7 years later..... |
I just hit this while trying to refactor some of our modules that define our AWS Transit Gateways. They had hard-coded IP blocks, but these were already available from the Terraform resources we have that define VPCs and their subnets. I spent a long time smashing my head against this limitation trying to make it so that additional regions wouldn't require any code changes, they could just be picked up from newly written Terraform state files. As far as I can tell it's not possible. There's no way to instantiate or pass a provider based on a data source. You can't One way to change Terraform to accommodate this: allow provider attributes to be overridden by resources. The only reason I need to pass different providers is because I need to target different AWS regions. My problem would be solved if I could set an explicit region on the resource that the provider could use when managing the resource. This is basically what folks do when managing AWS resources manually. They don't have to create a whole new profile, they can just set the |
Hi all! While doing some issue gardening today I noticed that this issue is covering a similar topic as #25244. Although this issue is older than that one, it looks like it's attracted more upvotes and has comment with a more up-to-date overview of the design challenges than we've had in this issue so far. Also, this issue seems to have started being about dynamic provider configuration assignment but later discussion is about dynamic provider configuration definition, which (as I noted in my comment over in the other issue) are two separate concerns from a technical design standpoint. Because of all this, I'm going to close this one in favor of #25244 just to consolidate the discussion. I also want to quickly respond to @adamsb6's comment, before I go: It is true that the AWS provider could in principle support setting the Therefore I think in practice we're essentially stuck with the idea that region is a per-provider-configuration setting for the |
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. |
I would like to be able to use a dynamic name for the provider alias inside of a resource definition. For example:
I would then call terraform like:
terraform plan -var hosting=rackspace
and it would use the openstack provider that is aliased asopenstack.rackspace
This would allow me to easily toggle my single terraform config between multiple environments & providers.
The text was updated successfully, but these errors were encountered: