From 9249a528c60731a627ea0682914665c236ed0a9a Mon Sep 17 00:00:00 2001 From: Kostas Evangelou Date: Wed, 16 Oct 2019 15:54:57 +0100 Subject: [PATCH 1/3] Make default metadata, labels and tags optional in beta private cluster --- modules/beta-private-cluster/cluster.tf | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/modules/beta-private-cluster/cluster.tf b/modules/beta-private-cluster/cluster.tf index c481c69a35..08332c4db5 100644 --- a/modules/beta-private-cluster/cluster.tf +++ b/modules/beta-private-cluster/cluster.tf @@ -243,22 +243,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -277,8 +269,8 @@ resource "google_container_node_pool" "pools" { } } tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) From dcb2b11ff4206110f54d79199c6fbf125edd0966 Mon Sep 17 00:00:00 2001 From: Kostas Evangelou Date: Wed, 16 Oct 2019 17:02:44 +0100 Subject: [PATCH 2/3] generate changes for all (sub)modules --- autogen/cluster.tf | 20 +++++------------ cluster.tf | 20 +++++------------ .../cluster.tf | 22 ++++++------------- modules/beta-public-cluster/cluster.tf | 20 +++++------------ .../private-cluster-update-variant/cluster.tf | 22 ++++++------------- modules/private-cluster/cluster.tf | 20 +++++------------ 6 files changed, 38 insertions(+), 86 deletions(-) diff --git a/autogen/cluster.tf b/autogen/cluster.tf index 296b2818df..5de8ad6876 100644 --- a/autogen/cluster.tf +++ b/autogen/cluster.tf @@ -341,22 +341,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -377,8 +369,8 @@ resource "google_container_node_pool" "pools" { } {% endif %} tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) diff --git a/cluster.tf b/cluster.tf index ffdb27b0fc..ba117abd3d 100644 --- a/cluster.tf +++ b/cluster.tf @@ -161,22 +161,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -184,8 +176,8 @@ resource "google_container_node_pool" "pools" { }, ) tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index cf1def945d..6b02e72750 100644 --- a/modules/beta-private-cluster-update-variant/cluster.tf +++ b/modules/beta-private-cluster-update-variant/cluster.tf @@ -315,22 +315,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -349,8 +341,8 @@ resource "google_container_node_pool" "pools" { } } tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) @@ -389,7 +381,7 @@ resource "google_container_node_pool" "pools" { } lifecycle { - ignore_changes = [initial_node_count] + ignore_changes = [initial_node_count] create_before_destroy = true } diff --git a/modules/beta-public-cluster/cluster.tf b/modules/beta-public-cluster/cluster.tf index a264e932b9..0ff13c98b2 100644 --- a/modules/beta-public-cluster/cluster.tf +++ b/modules/beta-public-cluster/cluster.tf @@ -238,22 +238,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -272,8 +264,8 @@ resource "google_container_node_pool" "pools" { } } tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) diff --git a/modules/private-cluster-update-variant/cluster.tf b/modules/private-cluster-update-variant/cluster.tf index e8db91a77a..19929ed7de 100644 --- a/modules/private-cluster-update-variant/cluster.tf +++ b/modules/private-cluster-update-variant/cluster.tf @@ -238,22 +238,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -261,8 +253,8 @@ resource "google_container_node_pool" "pools" { }, ) tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) @@ -293,7 +285,7 @@ resource "google_container_node_pool" "pools" { } lifecycle { - ignore_changes = [initial_node_count] + ignore_changes = [initial_node_count] create_before_destroy = true } diff --git a/modules/private-cluster/cluster.tf b/modules/private-cluster/cluster.tf index 412e8295ed..0a9df965ef 100644 --- a/modules/private-cluster/cluster.tf +++ b/modules/private-cluster/cluster.tf @@ -166,22 +166,14 @@ resource "google_container_node_pool" "pools" { image_type = lookup(var.node_pools[count.index], "image_type", "COS") machine_type = lookup(var.node_pools[count.index], "machine_type", "n1-standard-2") labels = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_labels, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_labels["all"], var.node_pools_labels[var.node_pools[count.index]["name"]], ) metadata = merge( - { - "cluster_name" = var.name - }, - { - "node_pool" = var.node_pools[count.index]["name"] - }, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {}, + lookup(lookup(var.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = var.node_pools[count.index]["name"] } : {}, var.node_pools_metadata["all"], var.node_pools_metadata[var.node_pools[count.index]["name"]], { @@ -189,8 +181,8 @@ resource "google_container_node_pool" "pools" { }, ) tags = concat( - ["gke-${var.name}"], - ["gke-${var.name}-${var.node_pools[count.index]["name"]}"], + lookup(var.node_pools_tags, "default_values", [true, true])[0] ? ["gke-${var.name}"] : [], + lookup(var.node_pools_tags, "default_values", [true, true])[1] ? ["gke-${var.name}-${var.node_pools[count.index]["name"]}"] : [], var.node_pools_tags["all"], var.node_pools_tags[var.node_pools[count.index]["name"]], ) From 970671f7d42705147a07e78375dced78332bdaab Mon Sep 17 00:00:00 2001 From: Kostas Evangelou Date: Wed, 16 Oct 2019 17:33:00 +0100 Subject: [PATCH 3/3] format tf files --- modules/beta-private-cluster-update-variant/cluster.tf | 2 +- modules/private-cluster-update-variant/cluster.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index 6b02e72750..5b3b769c9e 100644 --- a/modules/beta-private-cluster-update-variant/cluster.tf +++ b/modules/beta-private-cluster-update-variant/cluster.tf @@ -381,7 +381,7 @@ resource "google_container_node_pool" "pools" { } lifecycle { - ignore_changes = [initial_node_count] + ignore_changes = [initial_node_count] create_before_destroy = true } diff --git a/modules/private-cluster-update-variant/cluster.tf b/modules/private-cluster-update-variant/cluster.tf index 19929ed7de..c6d76de2e5 100644 --- a/modules/private-cluster-update-variant/cluster.tf +++ b/modules/private-cluster-update-variant/cluster.tf @@ -285,7 +285,7 @@ resource "google_container_node_pool" "pools" { } lifecycle { - ignore_changes = [initial_node_count] + ignore_changes = [initial_node_count] create_before_destroy = true }