From 72908b6e5c72b865aa2fad496358a278ffdead8c Mon Sep 17 00:00:00 2001 From: Sam Naser Date: Fri, 25 Mar 2022 15:23:54 -0700 Subject: [PATCH] Make GKE module cluster_name computed attribute --- autogen/main/outputs.tf.tmpl | 12 ++++++++++++ cluster.tf | 6 +++--- dns.tf | 6 +++--- examples/simple_zonal_with_asm/main.tf | 2 +- main.tf | 10 +++++----- modules/beta-autopilot-private-cluster/outputs.tf | 9 +++++++++ modules/beta-autopilot-public-cluster/outputs.tf | 9 +++++++++ .../beta-private-cluster-update-variant/outputs.tf | 10 ++++++++++ modules/beta-private-cluster/outputs.tf | 10 ++++++++++ .../beta-public-cluster-update-variant/outputs.tf | 10 ++++++++++ modules/beta-public-cluster/outputs.tf | 10 ++++++++++ modules/private-cluster-update-variant/outputs.tf | 10 ++++++++++ modules/private-cluster/outputs.tf | 10 ++++++++++ outputs.tf | 10 ++++++++++ 14 files changed, 112 insertions(+), 12 deletions(-) diff --git a/autogen/main/outputs.tf.tmpl b/autogen/main/outputs.tf.tmpl index bb3b09f1ce..b31a5dfbe0 100644 --- a/autogen/main/outputs.tf.tmpl +++ b/autogen/main/outputs.tf.tmpl @@ -24,6 +24,18 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + {% if autopilot_cluster != true %} + google_container_node_pool.pools, + {% endif %} + ] } output "type" { diff --git a/cluster.tf b/cluster.tf index a06712b2d1..1588517666 100644 --- a/cluster.tf +++ b/cluster.tf @@ -100,15 +100,15 @@ resource "google_container_cluster" "primary" { addons_config { http_load_balancing { - disabled = !var.http_load_balancing + disabled = ! var.http_load_balancing } horizontal_pod_autoscaling { - disabled = !var.horizontal_pod_autoscaling + disabled = ! var.horizontal_pod_autoscaling } network_policy_config { - disabled = !var.network_policy + disabled = ! var.network_policy } gcp_filestore_csi_driver_config { diff --git a/dns.tf b/dns.tf index 1a4c059a30..e4abfce89e 100644 --- a/dns.tf +++ b/dns.tf @@ -23,7 +23,7 @@ module "gcloud_delete_default_kube_dns_configmap" { source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper" version = "~> 3.1" - enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && !var.skip_provisioners + enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners cluster_name = google_container_cluster.primary.name cluster_location = google_container_cluster.primary.location project_id = var.project_id @@ -43,7 +43,7 @@ module "gcloud_delete_default_kube_dns_configmap" { Create kube-dns confimap *****************************************/ resource "kubernetes_config_map" "kube-dns" { - count = local.custom_kube_dns_config && !local.upstream_nameservers_config ? 1 : 0 + count = local.custom_kube_dns_config && ! local.upstream_nameservers_config ? 1 : 0 metadata { name = "kube-dns" @@ -68,7 +68,7 @@ EOF } resource "kubernetes_config_map" "kube-dns-upstream-namservers" { - count = !local.custom_kube_dns_config && local.upstream_nameservers_config ? 1 : 0 + count = ! local.custom_kube_dns_config && local.upstream_nameservers_config ? 1 : 0 metadata { name = "kube-dns" diff --git a/examples/simple_zonal_with_asm/main.tf b/examples/simple_zonal_with_asm/main.tf index 8953c8b55e..c7351435c3 100644 --- a/examples/simple_zonal_with_asm/main.tf +++ b/examples/simple_zonal_with_asm/main.tf @@ -33,7 +33,7 @@ data "google_project" "project" { module "gke" { source = "../../" project_id = var.project_id - name = "${local.cluster_type}-cluster${var.cluster_name_suffix}" + name = "test-prefix-cluster-test-suffix" regional = false region = var.region zones = var.zones diff --git a/main.tf b/main.tf index 24297b180f..b637049a28 100644 --- a/main.tf +++ b/main.tf @@ -133,11 +133,11 @@ locals { cluster_monitoring_service = local.cluster_output_monitoring_service cluster_node_pools_names = local.cluster_output_node_pools_names cluster_node_pools_versions = local.cluster_output_node_pools_versions - cluster_network_policy_enabled = !local.cluster_output_network_policy_enabled - cluster_http_load_balancing_enabled = !local.cluster_output_http_load_balancing_enabled - cluster_horizontal_pod_autoscaling_enabled = !local.cluster_output_horizontal_pod_autoscaling_enabled - workload_identity_enabled = !(var.identity_namespace == null || var.identity_namespace == "null") - cluster_workload_identity_config = !local.workload_identity_enabled ? [] : var.identity_namespace == "enabled" ? [{ + cluster_network_policy_enabled = ! local.cluster_output_network_policy_enabled + cluster_http_load_balancing_enabled = ! local.cluster_output_http_load_balancing_enabled + cluster_horizontal_pod_autoscaling_enabled = ! local.cluster_output_horizontal_pod_autoscaling_enabled + workload_identity_enabled = ! (var.identity_namespace == null || var.identity_namespace == "null") + cluster_workload_identity_config = ! local.workload_identity_enabled ? [] : var.identity_namespace == "enabled" ? [{ workload_pool = "${var.project_id}.svc.id.goog" }] : [{ workload_pool = var.identity_namespace }] diff --git a/modules/beta-autopilot-private-cluster/outputs.tf b/modules/beta-autopilot-private-cluster/outputs.tf index 6cdab1a5ce..aff0a340ac 100644 --- a/modules/beta-autopilot-private-cluster/outputs.tf +++ b/modules/beta-autopilot-private-cluster/outputs.tf @@ -24,6 +24,15 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + ] } output "type" { diff --git a/modules/beta-autopilot-public-cluster/outputs.tf b/modules/beta-autopilot-public-cluster/outputs.tf index 3d0d040736..44233aea24 100644 --- a/modules/beta-autopilot-public-cluster/outputs.tf +++ b/modules/beta-autopilot-public-cluster/outputs.tf @@ -24,6 +24,15 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + ] } output "type" { diff --git a/modules/beta-private-cluster-update-variant/outputs.tf b/modules/beta-private-cluster-update-variant/outputs.tf index 4377e2ee3e..3e354ee719 100644 --- a/modules/beta-private-cluster-update-variant/outputs.tf +++ b/modules/beta-private-cluster-update-variant/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" { diff --git a/modules/beta-private-cluster/outputs.tf b/modules/beta-private-cluster/outputs.tf index 4377e2ee3e..3e354ee719 100644 --- a/modules/beta-private-cluster/outputs.tf +++ b/modules/beta-private-cluster/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" { diff --git a/modules/beta-public-cluster-update-variant/outputs.tf b/modules/beta-public-cluster-update-variant/outputs.tf index 1fbf1d6aba..9694a0beab 100644 --- a/modules/beta-public-cluster-update-variant/outputs.tf +++ b/modules/beta-public-cluster-update-variant/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" { diff --git a/modules/beta-public-cluster/outputs.tf b/modules/beta-public-cluster/outputs.tf index 1fbf1d6aba..9694a0beab 100644 --- a/modules/beta-public-cluster/outputs.tf +++ b/modules/beta-public-cluster/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" { diff --git a/modules/private-cluster-update-variant/outputs.tf b/modules/private-cluster-update-variant/outputs.tf index 62f205cda7..1c6403b651 100644 --- a/modules/private-cluster-update-variant/outputs.tf +++ b/modules/private-cluster-update-variant/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" { diff --git a/modules/private-cluster/outputs.tf b/modules/private-cluster/outputs.tf index 62f205cda7..1c6403b651 100644 --- a/modules/private-cluster/outputs.tf +++ b/modules/private-cluster/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" { diff --git a/outputs.tf b/outputs.tf index c28719639a..f543eb8bb5 100644 --- a/outputs.tf +++ b/outputs.tf @@ -24,6 +24,16 @@ output "cluster_id" { output "name" { description = "Cluster name" value = local.cluster_name + depends_on = [ + /* Nominally, the cluster name is populated as soon as it is known to Terraform. + * However, the cluster may not be in a usable state yet. Therefore any + * resources dependent on the cluster being up will fail to deploy. With + * this explicit dependency, dependent resources can wait for the cluster + * to be up. + */ + google_container_cluster.primary, + google_container_node_pool.pools, + ] } output "type" {