From ee9fb3cb1e8a064b183b5f699cde215b646e16ef Mon Sep 17 00:00:00 2001 From: Sam Naser Date: Tue, 29 Mar 2022 15:47:22 -0700 Subject: [PATCH] Use cluster ID for name output --- autogen/main/main.tf.tmpl | 7 +++++++ autogen/main/outputs.tf.tmpl | 2 +- main.tf | 4 +++- modules/beta-autopilot-private-cluster/main.tf | 4 +++- modules/beta-autopilot-private-cluster/outputs.tf | 2 +- modules/beta-autopilot-public-cluster/main.tf | 4 +++- modules/beta-autopilot-public-cluster/outputs.tf | 2 +- modules/beta-private-cluster-update-variant/main.tf | 4 +++- modules/beta-private-cluster-update-variant/outputs.tf | 2 +- modules/beta-private-cluster/main.tf | 4 +++- modules/beta-private-cluster/outputs.tf | 2 +- modules/beta-public-cluster-update-variant/main.tf | 4 +++- modules/beta-public-cluster-update-variant/outputs.tf | 2 +- modules/beta-public-cluster/main.tf | 4 +++- modules/beta-public-cluster/outputs.tf | 2 +- modules/private-cluster-update-variant/main.tf | 4 +++- modules/private-cluster-update-variant/outputs.tf | 2 +- modules/private-cluster/main.tf | 4 +++- modules/private-cluster/outputs.tf | 2 +- outputs.tf | 2 +- 20 files changed, 44 insertions(+), 19 deletions(-) diff --git a/autogen/main/main.tf.tmpl b/autogen/main/main.tf.tmpl index 5afd74e756..527f77968b 100644 --- a/autogen/main/main.tf.tmpl +++ b/autogen/main/main.tf.tmpl @@ -175,6 +175,13 @@ locals { cluster_zones = sort(local.cluster_output_zones) cluster_name = local.cluster_output_name + {% if autopilot_cluster != true %} + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) + {% else %} + // cluster ID is in the form project/location/name + cluster_name_computed = element(split("/", local.cluster_id), length(split("/", local.cluster_id)) - 1) + {% endif %} cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/autogen/main/outputs.tf.tmpl b/autogen/main/outputs.tf.tmpl index b31a5dfbe0..1aa6dadae8 100644 --- a/autogen/main/outputs.tf.tmpl +++ b/autogen/main/outputs.tf.tmpl @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/main.tf b/main.tf index 24297b180f..199b87c26b 100644 --- a/main.tf +++ b/main.tf @@ -124,7 +124,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-autopilot-private-cluster/main.tf b/modules/beta-autopilot-private-cluster/main.tf index 779c6eb03c..fca66dfbeb 100644 --- a/modules/beta-autopilot-private-cluster/main.tf +++ b/modules/beta-autopilot-private-cluster/main.tf @@ -107,7 +107,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // cluster ID is in the form project/location/name + cluster_name_computed = element(split("/", local.cluster_id), length(split("/", local.cluster_id)) - 1) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-autopilot-private-cluster/outputs.tf b/modules/beta-autopilot-private-cluster/outputs.tf index aff0a340ac..b3b21d9053 100644 --- a/modules/beta-autopilot-private-cluster/outputs.tf +++ b/modules/beta-autopilot-private-cluster/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/beta-autopilot-public-cluster/main.tf b/modules/beta-autopilot-public-cluster/main.tf index cae98fa3c5..bed7c65d7f 100644 --- a/modules/beta-autopilot-public-cluster/main.tf +++ b/modules/beta-autopilot-public-cluster/main.tf @@ -106,7 +106,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // cluster ID is in the form project/location/name + cluster_name_computed = element(split("/", local.cluster_id), length(split("/", local.cluster_id)) - 1) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-autopilot-public-cluster/outputs.tf b/modules/beta-autopilot-public-cluster/outputs.tf index 44233aea24..0950df9513 100644 --- a/modules/beta-autopilot-public-cluster/outputs.tf +++ b/modules/beta-autopilot-public-cluster/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/beta-private-cluster-update-variant/main.tf b/modules/beta-private-cluster-update-variant/main.tf index acdae6152a..8f2e123e59 100644 --- a/modules/beta-private-cluster-update-variant/main.tf +++ b/modules/beta-private-cluster-update-variant/main.tf @@ -147,7 +147,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-private-cluster-update-variant/outputs.tf b/modules/beta-private-cluster-update-variant/outputs.tf index 3e354ee719..41152fa2b4 100644 --- a/modules/beta-private-cluster-update-variant/outputs.tf +++ b/modules/beta-private-cluster-update-variant/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/beta-private-cluster/main.tf b/modules/beta-private-cluster/main.tf index acdae6152a..8f2e123e59 100644 --- a/modules/beta-private-cluster/main.tf +++ b/modules/beta-private-cluster/main.tf @@ -147,7 +147,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-private-cluster/outputs.tf b/modules/beta-private-cluster/outputs.tf index 3e354ee719..41152fa2b4 100644 --- a/modules/beta-private-cluster/outputs.tf +++ b/modules/beta-private-cluster/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/beta-public-cluster-update-variant/main.tf b/modules/beta-public-cluster-update-variant/main.tf index 0f9683068f..9174ec019d 100644 --- a/modules/beta-public-cluster-update-variant/main.tf +++ b/modules/beta-public-cluster-update-variant/main.tf @@ -146,7 +146,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-public-cluster-update-variant/outputs.tf b/modules/beta-public-cluster-update-variant/outputs.tf index 9694a0beab..d05e54294d 100644 --- a/modules/beta-public-cluster-update-variant/outputs.tf +++ b/modules/beta-public-cluster-update-variant/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/beta-public-cluster/main.tf b/modules/beta-public-cluster/main.tf index 0f9683068f..9174ec019d 100644 --- a/modules/beta-public-cluster/main.tf +++ b/modules/beta-public-cluster/main.tf @@ -146,7 +146,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/beta-public-cluster/outputs.tf b/modules/beta-public-cluster/outputs.tf index 9694a0beab..d05e54294d 100644 --- a/modules/beta-public-cluster/outputs.tf +++ b/modules/beta-public-cluster/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/private-cluster-update-variant/main.tf b/modules/private-cluster-update-variant/main.tf index 5702f92d81..fbd544bf05 100644 --- a/modules/private-cluster-update-variant/main.tf +++ b/modules/private-cluster-update-variant/main.tf @@ -125,7 +125,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/private-cluster-update-variant/outputs.tf b/modules/private-cluster-update-variant/outputs.tf index 1c6403b651..4c17822106 100644 --- a/modules/private-cluster-update-variant/outputs.tf +++ b/modules/private-cluster-update-variant/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/modules/private-cluster/main.tf b/modules/private-cluster/main.tf index 5702f92d81..fbd544bf05 100644 --- a/modules/private-cluster/main.tf +++ b/modules/private-cluster/main.tf @@ -125,7 +125,9 @@ locals { cluster_region = var.regional ? var.region : join("-", slice(split("-", local.cluster_location), 0, 2)) cluster_zones = sort(local.cluster_output_zones) - cluster_name = local.cluster_output_name + cluster_name = local.cluster_output_name + // node pool ID is in the form project/location/cluster/name + cluster_name_computed = element(split("/", google_container_node_pool.pools.0.id), length(split("/", google_container_node_pool.pools.0.id)) - 2) cluster_network_tag = "gke-${var.name}" cluster_ca_certificate = local.cluster_master_auth_map["cluster_ca_certificate"] cluster_master_version = local.cluster_output_master_version diff --git a/modules/private-cluster/outputs.tf b/modules/private-cluster/outputs.tf index 1c6403b651..4c17822106 100644 --- a/modules/private-cluster/outputs.tf +++ b/modules/private-cluster/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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 diff --git a/outputs.tf b/outputs.tf index f543eb8bb5..414e662a17 100644 --- a/outputs.tf +++ b/outputs.tf @@ -23,7 +23,7 @@ output "cluster_id" { output "name" { description = "Cluster name" - value = local.cluster_name + value = local.cluster_name_computed 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