From 43b7728872cf31aec0a73e16d949d20f4cd9c579 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 ++++++++++++ examples/simple_zonal_with_asm/main.tf | 2 +- 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 ++++++++++ 11 files changed, 101 insertions(+), 1 deletion(-) 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/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/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" {