From 582236723b6b2895835d39e3b5fe77a7950859ed Mon Sep 17 00:00:00 2001 From: Taylor Ludwig Date: Fri, 8 Nov 2019 16:02:21 -0800 Subject: [PATCH] Fix node_count when autoscaling disabled on node pool. Fixes #311 Dont set initial_node_count when autoscaling is disabled on node pool. Use new node pool var when setting desired size of pool - matches provider var --- autogen/cluster.tf | 10 ++++++---- cluster.tf | 10 ++++++---- modules/beta-private-cluster-update-variant/cluster.tf | 10 ++++++---- modules/beta-private-cluster/cluster.tf | 10 ++++++---- modules/beta-public-cluster/cluster.tf | 10 ++++++---- modules/private-cluster-update-variant/cluster.tf | 10 ++++++---- modules/private-cluster/cluster.tf | 10 ++++++---- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/autogen/cluster.tf b/autogen/cluster.tf index 0bac34a37e..7353468cd7 100644 --- a/autogen/cluster.tf +++ b/autogen/cluster.tf @@ -316,16 +316,18 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + {% if beta_cluster %} max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null) {% endif %} - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : [] diff --git a/cluster.tf b/cluster.tf index 7e5f53ee47..072a60fb14 100644 --- a/cluster.tf +++ b/cluster.tf @@ -137,13 +137,15 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : [] diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index 6039cecd98..c92695ce49 100644 --- a/modules/beta-private-cluster-update-variant/cluster.tf +++ b/modules/beta-private-cluster-update-variant/cluster.tf @@ -290,14 +290,16 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null) - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : [] diff --git a/modules/beta-private-cluster/cluster.tf b/modules/beta-private-cluster/cluster.tf index 10e12a9ba0..fb9b1ee683 100644 --- a/modules/beta-private-cluster/cluster.tf +++ b/modules/beta-private-cluster/cluster.tf @@ -218,14 +218,16 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null) - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : [] diff --git a/modules/beta-public-cluster/cluster.tf b/modules/beta-public-cluster/cluster.tf index b5f896bc1b..88725475a8 100644 --- a/modules/beta-public-cluster/cluster.tf +++ b/modules/beta-public-cluster/cluster.tf @@ -213,14 +213,16 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + max_pods_per_node = lookup(var.node_pools[count.index], "max_pods_per_node", null) - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : [] diff --git a/modules/private-cluster-update-variant/cluster.tf b/modules/private-cluster-update-variant/cluster.tf index 615fe84bcc..d7fc2dd736 100644 --- a/modules/private-cluster-update-variant/cluster.tf +++ b/modules/private-cluster-update-variant/cluster.tf @@ -214,13 +214,15 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : [] diff --git a/modules/private-cluster/cluster.tf b/modules/private-cluster/cluster.tf index 3c42e64325..c8051255bf 100644 --- a/modules/private-cluster/cluster.tf +++ b/modules/private-cluster/cluster.tf @@ -142,13 +142,15 @@ resource "google_container_node_pool" "pools" { "version", local.node_version, ) - initial_node_count = lookup( + + initial_node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? lookup( var.node_pools[count.index], "initial_node_count", - lookup(var.node_pools[count.index], "min_count", 1), - ) + lookup(var.node_pools[count.index], "min_count", 1) + ) : null + - node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "min_count", 1) + node_count = lookup(var.node_pools[count.index], "autoscaling", true) ? null : lookup(var.node_pools[count.index], "node_count", 1) dynamic "autoscaling" { for_each = lookup(var.node_pools[count.index], "autoscaling", true) ? [var.node_pools[count.index]] : []