I'm new to Terraform
, I need suggestion about handling one case where I need to use data from counted
data-source
to un-counted
provider
.
I need to fetch the gke-cluster
context and pass it to provider helm/kubernetes
to provision resources on it .
There can be multiple gke -clusters
, so I'm using count
on the data-source google_container_cluster
and then I was trying to get the endpoint
from it .
Like below :
data "google_container_cluster" "my_cluster" {
count = var.enabled ? length(var.gke_clusters) : 0
location = lookup(var.gke_clusters[count.index], "cluster_location")
name = lookup(var.gke_clusters[count.index], "cluster_name")
}
provider "helm" {
kubernetes {
host = "https://${data.google_container_cluster.my_cluster.endpoint}"
token = data.google_client_config.provider.access_token
cluster_ca_certificate = base64decode(
data.google_container_cluster.my_cluster.master_auth[0].cluster_ca_certificate,
)
}
}
But this does not work because when I'm referring to my_cluster
I have to specify the index
, and if I specify the index my_cluster[count.index]
, I get an error that Error: Reference to "count" in non-counted context
.
Thanks in advance.