Connect to GKE cluster dynamically using terraform

6/11/2020

I am using Terraform script to spin up a GKE cluster and then use helm 3 to install splunk connector on the cluster.

How do I connect to the newly created cluster in terraform kubernetes provider dynamically ?

-- Spartan87
google-kubernetes-engine
kubernetes
kubernetes-helm
splunk
terraform

1 Answer

6/11/2020

Let the provider depend on the cluster certificate:

data "google_client_config" "terraform_config" {
  provider = google
}

provider "kubernetes" {
  load_config_file = false
  host = "https://${google_container_cluster.my_cluster.endpoint}"
  cluster_ca_certificate = base64decode(google_container_cluster.my_cluster.master_auth[0].cluster_ca_certificate)
  token = data.google_client_config.terraform_config.access_token
}
-- Frederik Bode
Source: StackOverflow