From dd2afca273e32b37b5bcbd98ad42e4f0b633c43a Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Fri, 15 May 2020 12:33:56 -0400 Subject: [PATCH] fix: Update auth module to handle empty clusters (#521) --- modules/auth/main.tf | 13 ++++++++++--- modules/auth/outputs.tf | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/auth/main.tf b/modules/auth/main.tf index 25855d842..e15273b88 100644 --- a/modules/auth/main.tf +++ b/modules/auth/main.tf @@ -14,6 +14,13 @@ * limitations under the License. */ +locals { + cluster_ca_certificate = data.google_container_cluster.gke_cluster.master_auth != null ? data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate : "" + endpoint = data.google_container_cluster.gke_cluster.endpoint != null ? data.google_container_cluster.gke_cluster.endpoint : "" + host = data.google_container_cluster.gke_cluster.endpoint != null ? "https://${data.google_container_cluster.gke_cluster.endpoint}" : "" + context = data.google_container_cluster.gke_cluster.name != null ? data.google_container_cluster.gke_cluster.name : "" +} + data "google_container_cluster" "gke_cluster" { name = var.cluster_name location = var.location @@ -26,9 +33,9 @@ data "template_file" "kubeconfig" { template = file("${path.module}/templates/kubeconfig-template.yaml.tpl") vars = { - context = data.google_container_cluster.gke_cluster.name - cluster_ca_certificate = data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate - endpoint = data.google_container_cluster.gke_cluster.endpoint + context = local.context + cluster_ca_certificate = local.cluster_ca_certificate + endpoint = local.endpoint token = data.google_client_config.provider.access_token } } diff --git a/modules/auth/outputs.tf b/modules/auth/outputs.tf index a33ef81f7..5f25a316f 100644 --- a/modules/auth/outputs.tf +++ b/modules/auth/outputs.tf @@ -27,12 +27,12 @@ output "kubeconfig_raw" { output "cluster_ca_certificate" { sensitive = true description = "The cluster_ca_certificate value for use with the kubernetes provider." - value = base64decode(data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate) + value = base64decode(local.cluster_ca_certificate) } output "host" { description = "The host value for use with the kubernetes provider." - value = "https://${data.google_container_cluster.gke_cluster.endpoint}" + value = local.host } output "token" {