Hi, i have to deploy the same config to multiple providers, so want to do something like:
locals {
provider_names = toset([helm, helm.prod])
}
resource "helm_release" "kubernetes_dashboard" {
for_each = local.provider_names
provider = each.key
…except terraform init complains:
Error while installing hashicorp/each: provider registry registry.terraform.io
does not have a provider named registry.terraform.io/hashicorp/each
Hi @gilbertgrant,
The association between resources and their provider configurations is static because Terraform needs to know it before it can perform any other work with a resource
block, and because the association must also be recorded in the state to allow Terraform to later potentially destroy the object when its configuration is no longer present in the configuration.
The closest you can get to your goal with the Terraform language today is to factor out the per-environment part of your system into a child module and then instantiate that module twice, passing a different provider configuration each time:
module "example" {
source = "./modules/per-environment"
providers = {
# The default "helm" configuration in the
# child module will be the same as the
# default configuration in the parent.
helm = helm
}
# ...
}
module "example_prod" {
source = "./modules/per-environment"
providers = {
# The default "helm" configuration in the
# child module will be the same as the
# "prod" aliased configuration in the parent.
helm = helm.prod
}
# ...
}
Inside the module you can write helm
provider resources with no explicit provider argument, and those resources will be associated with whichever configuration the root module chooses for that module.
1 Like