Skip to content

Commit

Permalink
fix: Update auth module to handle empty clusters (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed May 15, 2020
1 parent 9195f0f commit dd2afca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions modules/auth/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
4 changes: 2 additions & 2 deletions modules/auth/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit dd2afca

Please sign in to comment.