From a84ef9f6b102589f378dd2e76a21cca0406d3d8c Mon Sep 17 00:00:00 2001 From: pk0331 <105767668+pk0331@users.noreply.github.com> Date: Tue, 30 Aug 2022 17:55:59 +0530 Subject: [PATCH] Gke remove default np (#3) Changes for removing default nodepool --- modules/private-cluster/cluster.tf | 51 +++------------------------- modules/private-cluster/variables.tf | 15 ++------ 2 files changed, 8 insertions(+), 58 deletions(-) diff --git a/modules/private-cluster/cluster.tf b/modules/private-cluster/cluster.tf index 199cda3d9e..1544a88377 100644 --- a/modules/private-cluster/cluster.tf +++ b/modules/private-cluster/cluster.tf @@ -130,7 +130,7 @@ resource "google_container_cluster" "primary" { } lifecycle { - ignore_changes = [node_pool, initial_node_count, resource_labels["asmv"], resource_labels["mesh_id"]] + ignore_changes = [initial_node_count, resource_labels["asmv"], resource_labels["mesh_id"]] } timeouts { @@ -138,49 +138,10 @@ resource "google_container_cluster" "primary" { update = "45m" delete = "45m" } - node_pool { - name = "default-pool" - initial_node_count = var.initial_node_count - - node_config { - image_type = lookup(var.node_pools[0], "image_type", "COS_CONTAINERD") - machine_type = lookup(var.node_pools[0], "machine_type", "e2-medium") - min_cpu_platform = lookup(var.node_pools[0], "min_cpu_platform", "") - disk_size_gb = lookup(var.node_pools[0], "disk_size_gb", 30) - disk_type = lookup(var.node_pools[0], "disk_type", "pd-balanced") - dynamic "gcfs_config" { - for_each = lookup(var.node_pools[0], "enable_gcfs", false) ? [true] : [] - content { - enabled = gcfs_config.value - } - } - - service_account = lookup(var.node_pools[0], "service_account", local.service_account) - - tags = concat( - lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [], - lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [], - lookup(local.node_pools_tags, "all", []), - lookup(local.node_pools_tags, var.node_pools[0].name, []), - ) - - dynamic "workload_metadata_config" { - for_each = local.cluster_node_metadata_config - - content { - mode = workload_metadata_config.value.mode - } - } - - metadata = local.node_pools_metadata["all"] - - - shielded_instance_config { - enable_secure_boot = lookup(var.node_pools[0], "enable_secure_boot", false) - enable_integrity_monitoring = lookup(var.node_pools[0], "enable_integrity_monitoring", true) - } - } - } + ##Since we are removing default nodepool, the following attribute must be set along side remove_default_node_pool + ## From Terraform docs: Must be set if node_pool is not set. + initial_node_count = var.initial_node_count + remove_default_node_pool = var.remove_default_node_pool dynamic "resource_usage_export_config" { for_each = var.resource_usage_export_dataset_id != "" ? [{ @@ -212,8 +173,6 @@ resource "google_container_cluster" "primary" { } } - remove_default_node_pool = var.remove_default_node_pool - dynamic "database_encryption" { for_each = var.database_encryption diff --git a/modules/private-cluster/variables.tf b/modules/private-cluster/variables.tf index 17a02fb465..164046d16f 100644 --- a/modules/private-cluster/variables.tf +++ b/modules/private-cluster/variables.tf @@ -129,11 +129,7 @@ variable "node_pools" { type = list(map(string)) description = "List of maps containing node pools" - default = [ - { - name = "default-node-pool" - }, - ] + default = [] } variable "node_pools_labels" { @@ -143,7 +139,6 @@ variable "node_pools_labels" { # Default is being set in variables_defaults.tf default = { all = {} - default-node-pool = {} } } @@ -154,7 +149,6 @@ variable "node_pools_metadata" { # Default is being set in variables_defaults.tf default = { all = {} - default-node-pool = {} } } @@ -203,7 +197,6 @@ variable "node_pools_taints" { # Default is being set in variables_defaults.tf default = { all = [] - default-node-pool = [] } } @@ -214,7 +207,6 @@ variable "node_pools_tags" { # Default is being set in variables_defaults.tf default = { all = [] - default-node-pool = [] } } @@ -225,7 +217,6 @@ variable "node_pools_oauth_scopes" { # Default is being set in variables_defaults.tf default = { all = ["https://www.googleapis.com/auth/cloud-platform"] - default-node-pool = [] } } @@ -419,13 +410,13 @@ variable "network_policy_provider" { variable "initial_node_count" { type = number description = "The number of nodes to create in this cluster's default node pool." - default = 0 + default = 1 } variable "remove_default_node_pool" { type = bool description = "Remove default node pool while setting up the cluster" - default = false + default = true } variable "filestore_csi_driver" {