Send output to provider

I’m about to create a couple of k8s clusters with for_each and got stuck with one Q, how to send output to kubernetes provider? I can’t iterate through the provider:

output "instances" {
  sensitive = true
  value = tomap({
    for k, inst in google_container_cluster.cluster : k => {
      endpoint                = inst.endpoint
      client_certificate      = inst.master_auth.0.client_certificate 
      client_key              = inst.master_auth.0.client_key
      cluster_ca_certificate  = inst.master_auth.0.cluster_ca_certificate
  description = "kubeconfig"

When you say “send output to the kubernetes provider” are you meaning you have a provider block for the kubenetes provider that you are trying to set to those values?

When you use the Kubernetes provider it refers to a single K8S cluster. So if you are wanting to have the ability to configure multiple clusters in a single chunk of Terraform code you would need multiple provider blocks (with aliases).

yes, I have the provider block. I’m thinking about aliases, but aliases should be predefined, I can’t add aliases as a dynamic list of values, right? my idea was creating n k8s clusters and dynamically apply a couple of manifests after creation.

That’s not possible within the same piece of Terraform code.

Providers aren’t dynamic, as they have to be created when Terraform starts to handle the dependency graph creation, and because you have to set aliases.

1 Like