Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update auth module to handle empty clusters #521

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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