Skip to content

Commit b8b8547

Browse files
authored
fix: Allow users to specify network tags for the default node pool (#1123)
* Modify cluster template to allow setting network tags on default-pool This adds the following tags to the default pool: * the cluster_network_tag (gke-${var.name}) * the pool-specific network tag (gke-${var.name}-default-pool) * user-specified tags from var.node_pools_tags["all"]\ * user-specified tags from var.node_pools_tags["default-pool"] * Build autogen template to apply changes in cluster.tf.impl * Use network tags from the first node pool
1 parent 14a0536 commit b8b8547

File tree

8 files changed

+56
-0
lines changed

8 files changed

+56
-0
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ resource "google_container_cluster" "primary" {
288288

289289
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
290290

291+
tags = concat(
292+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
293+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
294+
lookup(local.node_pools_tags, "all", []),
295+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
296+
)
297+
291298
dynamic "workload_metadata_config" {
292299
for_each = local.cluster_node_metadata_config
293300

cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ resource "google_container_cluster" "primary" {
152152

153153
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
154154

155+
tags = concat(
156+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
157+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
158+
lookup(local.node_pools_tags, "all", []),
159+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
160+
)
161+
155162
dynamic "workload_metadata_config" {
156163
for_each = local.cluster_node_metadata_config
157164

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {
253253

254254
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
255255

256+
tags = concat(
257+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
258+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
259+
lookup(local.node_pools_tags, "all", []),
260+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
261+
)
262+
256263
dynamic "workload_metadata_config" {
257264
for_each = local.cluster_node_metadata_config
258265

modules/beta-private-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {
253253

254254
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
255255

256+
tags = concat(
257+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
258+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
259+
lookup(local.node_pools_tags, "all", []),
260+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
261+
)
262+
256263
dynamic "workload_metadata_config" {
257264
for_each = local.cluster_node_metadata_config
258265

modules/beta-public-cluster-update-variant/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {
253253

254254
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
255255

256+
tags = concat(
257+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
258+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
259+
lookup(local.node_pools_tags, "all", []),
260+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
261+
)
262+
256263
dynamic "workload_metadata_config" {
257264
for_each = local.cluster_node_metadata_config
258265

modules/beta-public-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {
253253

254254
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
255255

256+
tags = concat(
257+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
258+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
259+
lookup(local.node_pools_tags, "all", []),
260+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
261+
)
262+
256263
dynamic "workload_metadata_config" {
257264
for_each = local.cluster_node_metadata_config
258265

modules/private-cluster-update-variant/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ resource "google_container_cluster" "primary" {
152152

153153
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
154154

155+
tags = concat(
156+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
157+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
158+
lookup(local.node_pools_tags, "all", []),
159+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
160+
)
161+
155162
dynamic "workload_metadata_config" {
156163
for_each = local.cluster_node_metadata_config
157164

modules/private-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ resource "google_container_cluster" "primary" {
152152

153153
service_account = lookup(var.node_pools[0], "service_account", local.service_account)
154154

155+
tags = concat(
156+
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
157+
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
158+
lookup(local.node_pools_tags, "all", []),
159+
lookup(local.node_pools_tags, var.node_pools[0].name, []),
160+
)
161+
155162
dynamic "workload_metadata_config" {
156163
for_each = local.cluster_node_metadata_config
157164

0 commit comments

Comments
 (0)