Skip to content

Commit dd2afca

Browse files
authored
fix: Update auth module to handle empty clusters (#521)
1 parent 9195f0f commit dd2afca

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

modules/auth/main.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
locals {
18+
cluster_ca_certificate = data.google_container_cluster.gke_cluster.master_auth != null ? data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate : ""
19+
endpoint = data.google_container_cluster.gke_cluster.endpoint != null ? data.google_container_cluster.gke_cluster.endpoint : ""
20+
host = data.google_container_cluster.gke_cluster.endpoint != null ? "https://${data.google_container_cluster.gke_cluster.endpoint}" : ""
21+
context = data.google_container_cluster.gke_cluster.name != null ? data.google_container_cluster.gke_cluster.name : ""
22+
}
23+
1724
data "google_container_cluster" "gke_cluster" {
1825
name = var.cluster_name
1926
location = var.location
@@ -26,9 +33,9 @@ data "template_file" "kubeconfig" {
2633
template = file("${path.module}/templates/kubeconfig-template.yaml.tpl")
2734

2835
vars = {
29-
context = data.google_container_cluster.gke_cluster.name
30-
cluster_ca_certificate = data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate
31-
endpoint = data.google_container_cluster.gke_cluster.endpoint
36+
context = local.context
37+
cluster_ca_certificate = local.cluster_ca_certificate
38+
endpoint = local.endpoint
3239
token = data.google_client_config.provider.access_token
3340
}
3441
}

modules/auth/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ output "kubeconfig_raw" {
2727
output "cluster_ca_certificate" {
2828
sensitive = true
2929
description = "The cluster_ca_certificate value for use with the kubernetes provider."
30-
value = base64decode(data.google_container_cluster.gke_cluster.master_auth[0].cluster_ca_certificate)
30+
value = base64decode(local.cluster_ca_certificate)
3131
}
3232

3333
output "host" {
3434
description = "The host value for use with the kubernetes provider."
35-
value = "https://${data.google_container_cluster.gke_cluster.endpoint}"
35+
value = local.host
3636
}
3737

3838
output "token" {

0 commit comments

Comments
 (0)