I would like to deploy a helm chart to multiple projects. I have already created a GKE cluster in each project using:
locals {
local.project_ids = [
# list of projects in which I want to create a kube cluster
# See https://discuss.hashicorp.com/t/add-element-to-a-map-where-the-value-depends-on-some-expression/24761/5
# for how this was done
]
}
resource "google_service_account" "gke" {
for_each = local.project_ids
project = each.key
account_id = "kube-sa"
display_name = "gke sa"
}
resource "google_container_cluster" "primary" {
for_each = local.project_ids
project = each.key
name = "my-gke-cluster"
location = var.region
network = google_compute_network.network[each.key].self_link
subnetwork = google_compute_subnetwork.europe_west2[each.key].self_link
# We can't create a cluster with no node pool defined, but we want to only use
# separately managed node pools. So we create the smallest possible default
# node pool and immediately delete it.
remove_default_node_pool = true
initial_node_count = 1
}
resource "google_container_node_pool" "primary_preemptible_nodes" {
for_each = local.project_ids
project = each.key
name = "my-node-pool"
location = var.region
cluster = google_container_cluster.primary[each.key].name
node_count = 1
node_config {
preemptible = true
machine_type = "e2-medium"
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
service_account = google_service_account.gke[each.key].email
oauth_scopes = [
"https://www.googleapis.com/auth/cloud-platform"
]
}
}
I’m aware there is a helm provider (https://registry.terraform.io/providers/hashicorp/helm/latest) and from this useful blog post: How to Deploy ElasticSearch on GKE using Terraform and Helm - Binx I’ve gleaned that it can be configured like so:
provider "helm" {
kubernetes {
token = data.google_client_config.client.access_token
host = data.google_container_cluster.gke.endpoint
cluster_ca_certificate = base64decode(data.google_container_cluster.gke.master_auth[0].cluster_ca_certificate)
}
}
The trouble I have though is that the helm provider configuration requires specification of a cluster but I have multiple clusters, one in each project.
Is there a way to configure multiple instances of the helm provider, one for each of my GKE clusters?