From 64ac89d59c18e3b6b4034b3fd521cf60e33dcaba Mon Sep 17 00:00:00 2001 From: Deepak Kumar <21131061+kumadee@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:17:48 +0200 Subject: [PATCH] fix: allow disabling node autoprovisioning (#2238) - This fix allows a GKE Standard cluster to be configured with no auto-provisioned node pool, but allow setting autocluster profile for user-provisioned node pools like created via `gke-nodepool` module. Co-authored-by: Julio Castillo --- modules/gke-cluster-standard/README.md | 42 +++++++++++------------ modules/gke-cluster-standard/main.tf | 2 +- modules/gke-cluster-standard/variables.tf | 1 + 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md index 286b20a3dc..c53017267f 100644 --- a/modules/gke-cluster-standard/README.md +++ b/modules/gke-cluster-standard/README.md @@ -310,28 +310,28 @@ module "cluster-1" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [location](variables.tf#L233) | Cluster zone or region. | string | ✓ | | -| [name](variables.tf#L368) | Cluster name. | string | ✓ | | -| [project_id](variables.tf#L404) | Cluster project id. | string | ✓ | | -| [vpc_config](variables.tf#L415) | VPC-level configuration. | object({…}) | ✓ | | +| [location](variables.tf#L234) | Cluster zone or region. | string | ✓ | | +| [name](variables.tf#L369) | Cluster name. | string | ✓ | | +| [project_id](variables.tf#L405) | Cluster project id. | string | ✓ | | +| [vpc_config](variables.tf#L416) | VPC-level configuration. | object({…}) | ✓ | | | [backup_configs](variables.tf#L17) | Configuration for Backup for GKE. | object({…}) | | {} | -| [cluster_autoscaling](variables.tf#L38) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…}) | | null | -| [default_nodepool](variables.tf#L116) | Enable default nodepool. | object({…}) | | {} | -| [deletion_protection](variables.tf#L134) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | bool | | true | -| [description](variables.tf#L141) | Cluster description. | string | | null | -| [enable_addons](variables.tf#L147) | Addons enabled in the cluster (true means enabled). | object({…}) | | {…} | -| [enable_features](variables.tf#L171) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {…} | -| [issue_client_certificate](variables.tf#L221) | Enable issuing client certificate. | bool | | false | -| [labels](variables.tf#L227) | Cluster resource labels. | map(string) | | null | -| [logging_config](variables.tf#L238) | Logging configuration. | object({…}) | | {} | -| [maintenance_config](variables.tf#L259) | Maintenance window configuration. | object({…}) | | {…} | -| [max_pods_per_node](variables.tf#L282) | Maximum number of pods per node in this cluster. | number | | 110 | -| [min_master_version](variables.tf#L288) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | -| [monitoring_config](variables.tf#L294) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | -| [node_config](variables.tf#L373) | Node-level configuration. | object({…}) | | {} | -| [node_locations](variables.tf#L383) | Zones in which the cluster's nodes are located. | list(string) | | [] | -| [private_cluster_config](variables.tf#L390) | Private cluster configuration. | object({…}) | | null | -| [release_channel](variables.tf#L409) | Release channel for GKE upgrades. | string | | null | +| [cluster_autoscaling](variables.tf#L38) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…}) | | null | +| [default_nodepool](variables.tf#L117) | Enable default nodepool. | object({…}) | | {} | +| [deletion_protection](variables.tf#L135) | Whether or not to allow Terraform to destroy the cluster. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the cluster will fail. | bool | | true | +| [description](variables.tf#L142) | Cluster description. | string | | null | +| [enable_addons](variables.tf#L148) | Addons enabled in the cluster (true means enabled). | object({…}) | | {…} | +| [enable_features](variables.tf#L172) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {…} | +| [issue_client_certificate](variables.tf#L222) | Enable issuing client certificate. | bool | | false | +| [labels](variables.tf#L228) | Cluster resource labels. | map(string) | | null | +| [logging_config](variables.tf#L239) | Logging configuration. | object({…}) | | {} | +| [maintenance_config](variables.tf#L260) | Maintenance window configuration. | object({…}) | | {…} | +| [max_pods_per_node](variables.tf#L283) | Maximum number of pods per node in this cluster. | number | | 110 | +| [min_master_version](variables.tf#L289) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | +| [monitoring_config](variables.tf#L295) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | +| [node_config](variables.tf#L374) | Node-level configuration. | object({…}) | | {} | +| [node_locations](variables.tf#L384) | Zones in which the cluster's nodes are located. | list(string) | | [] | +| [private_cluster_config](variables.tf#L391) | Private cluster configuration. | object({…}) | | null | +| [release_channel](variables.tf#L410) | Release channel for GKE upgrades. | string | | null | ## Outputs diff --git a/modules/gke-cluster-standard/main.tf b/modules/gke-cluster-standard/main.tf index 6ab4c9d881..99db49f80d 100644 --- a/modules/gke-cluster-standard/main.tf +++ b/modules/gke-cluster-standard/main.tf @@ -132,7 +132,7 @@ resource "google_container_cluster" "cluster" { dynamic "cluster_autoscaling" { for_each = local.cas == null ? [] : [""] content { - enabled = true + enabled = var.cluster_autoscaling.enabled autoscaling_profile = var.cluster_autoscaling.autoscaling_profile dynamic "auto_provisioning_defaults" { for_each = local.cas_apd != null ? [""] : [] diff --git a/modules/gke-cluster-standard/variables.tf b/modules/gke-cluster-standard/variables.tf index 6644595494..5580320f8f 100644 --- a/modules/gke-cluster-standard/variables.tf +++ b/modules/gke-cluster-standard/variables.tf @@ -38,6 +38,7 @@ variable "backup_configs" { variable "cluster_autoscaling" { description = "Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler." type = object({ + enabled = optional(bool, true) autoscaling_profile = optional(string, "BALANCED") auto_provisioning_defaults = optional(object({ boot_disk_kms_key = optional(string)