From 9c62f1f53afacf664528f9b3187c7e5df8eea1fa Mon Sep 17 00:00:00 2001 From: shubham kumar singh Date: Wed, 22 Nov 2023 12:58:47 +0530 Subject: [PATCH] feat: add support for pod_range in private cluster (#1803) Co-authored-by: Shubham Singh --- autogen/main/cluster.tf.tmpl | 2 -- cluster.tf | 28 +++++++++++++++++++ .../private-cluster-update-variant/cluster.tf | 28 +++++++++++++++++++ modules/private-cluster/cluster.tf | 28 +++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/autogen/main/cluster.tf.tmpl b/autogen/main/cluster.tf.tmpl index 577dc312f5..459f4f712c 100644 --- a/autogen/main/cluster.tf.tmpl +++ b/autogen/main/cluster.tf.tmpl @@ -714,7 +714,6 @@ resource "google_container_node_pool" "windows_pools" { } } - {% if beta_cluster %} dynamic "placement_policy" { for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] content { @@ -733,7 +732,6 @@ resource "google_container_node_pool" "windows_pools" { {% endif %} } } - {% endif %} management { auto_repair = lookup(each.value, "auto_repair", true) diff --git a/cluster.tf b/cluster.tf index 2332cc8e26..3f8c070a61 100644 --- a/cluster.tf +++ b/cluster.tf @@ -436,6 +436,20 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + + dynamic "network_config" { + for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] + content { + pod_range = lookup(network_config.value, "pod_range", null) + enable_private_nodes = lookup(network_config.value, "enable_private_nodes", null) + } + } management { auto_repair = lookup(each.value, "auto_repair", true) @@ -631,6 +645,20 @@ resource "google_container_node_pool" "windows_pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + + dynamic "network_config" { + for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] + content { + pod_range = lookup(network_config.value, "pod_range", null) + enable_private_nodes = lookup(network_config.value, "enable_private_nodes", null) + } + } management { auto_repair = lookup(each.value, "auto_repair", true) diff --git a/modules/private-cluster-update-variant/cluster.tf b/modules/private-cluster-update-variant/cluster.tf index aa9cd45ea9..a6bbfa9b59 100644 --- a/modules/private-cluster-update-variant/cluster.tf +++ b/modules/private-cluster-update-variant/cluster.tf @@ -530,6 +530,20 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + + dynamic "network_config" { + for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] + content { + pod_range = lookup(network_config.value, "pod_range", null) + enable_private_nodes = var.enable_private_nodes + } + } management { auto_repair = lookup(each.value, "auto_repair", true) @@ -726,6 +740,20 @@ resource "google_container_node_pool" "windows_pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + + dynamic "network_config" { + for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] + content { + pod_range = lookup(network_config.value, "pod_range", null) + enable_private_nodes = var.enable_private_nodes + } + } management { auto_repair = lookup(each.value, "auto_repair", true) diff --git a/modules/private-cluster/cluster.tf b/modules/private-cluster/cluster.tf index f9c3266a6b..e8eefa20df 100644 --- a/modules/private-cluster/cluster.tf +++ b/modules/private-cluster/cluster.tf @@ -455,6 +455,20 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + + dynamic "network_config" { + for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] + content { + pod_range = lookup(network_config.value, "pod_range", null) + enable_private_nodes = var.enable_private_nodes + } + } management { auto_repair = lookup(each.value, "auto_repair", true) @@ -650,6 +664,20 @@ resource "google_container_node_pool" "windows_pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + + dynamic "network_config" { + for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] + content { + pod_range = lookup(network_config.value, "pod_range", null) + enable_private_nodes = var.enable_private_nodes + } + } management { auto_repair = lookup(each.value, "auto_repair", true)