diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md index ef61ea47e5..c7b1c4edde 100644 --- a/modules/gke-cluster-standard/README.md +++ b/modules/gke-cluster-standard/README.md @@ -3,7 +3,7 @@ This module offers a way to create and manage Google Kubernetes Engine (GKE) [Standard clusters](https://cloud.google.com/kubernetes-engine/docs/concepts/choose-cluster-mode#why-standard). With its sensible default settings based on best practices and authors' experience as Google Cloud practitioners, the module accommodates for many common use cases out-of-the-box, without having to rely on verbose configuration. > [!IMPORTANT] -> This module should be used together with the [`gke-nodepool`](../gke-nodepool/) module because the default node pool is deleted upon cluster creation and cannot be re-created. +> This module should be used together with the [`gke-nodepool`](../gke-nodepool/) module because the default node pool is deleted upon cluster creation by default. - [Example](#example) @@ -310,27 +310,28 @@ module "cluster-1" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [location](variables.tf#L214) | Cluster zone or region. | string | ✓ | | -| [name](variables.tf#L349) | Cluster name. | string | ✓ | | -| [project_id](variables.tf#L385) | Cluster project id. | string | ✓ | | -| [vpc_config](variables.tf#L396) | VPC-level configuration. | object({…}) | ✓ | | +| [location](variables.tf#L231) | Cluster zone or region. | string | ✓ | | +| [name](variables.tf#L366) | Cluster name. | string | ✓ | | +| [project_id](variables.tf#L402) | Cluster project id. | string | ✓ | | +| [vpc_config](variables.tf#L413) | 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 | -| [deletion_protection](variables.tf#L116) | 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#L123) | Cluster description. | string | | null | -| [enable_addons](variables.tf#L129) | Addons enabled in the cluster (true means enabled). | object({…}) | | {…} | -| [enable_features](variables.tf#L153) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {…} | -| [issue_client_certificate](variables.tf#L202) | Enable issuing client certificate. | bool | | false | -| [labels](variables.tf#L208) | Cluster resource labels. | map(string) | | null | -| [logging_config](variables.tf#L219) | Logging configuration. | object({…}) | | {} | -| [maintenance_config](variables.tf#L240) | Maintenance window configuration. | object({…}) | | {…} | -| [max_pods_per_node](variables.tf#L263) | Maximum number of pods per node in this cluster. | number | | 110 | -| [min_master_version](variables.tf#L269) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | -| [monitoring_config](variables.tf#L275) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | -| [node_config](variables.tf#L354) | Node-level configuration. | object({…}) | | {} | -| [node_locations](variables.tf#L364) | Zones in which the cluster's nodes are located. | list(string) | | [] | -| [private_cluster_config](variables.tf#L371) | Private cluster configuration. | object({…}) | | null | -| [release_channel](variables.tf#L390) | Release channel for GKE upgrades. | string | | null | +| [default_node_pool](variables.tf#L116) | Enable default node-pool. | object({…}) | | {…} | +| [deletion_protection](variables.tf#L133) | 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#L140) | Cluster description. | string | | null | +| [enable_addons](variables.tf#L146) | Addons enabled in the cluster (true means enabled). | object({…}) | | {…} | +| [enable_features](variables.tf#L170) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {…} | +| [issue_client_certificate](variables.tf#L219) | Enable issuing client certificate. | bool | | false | +| [labels](variables.tf#L225) | Cluster resource labels. | map(string) | | null | +| [logging_config](variables.tf#L236) | Logging configuration. | object({…}) | | {} | +| [maintenance_config](variables.tf#L257) | Maintenance window configuration. | object({…}) | | {…} | +| [max_pods_per_node](variables.tf#L280) | Maximum number of pods per node in this cluster. | number | | 110 | +| [min_master_version](variables.tf#L286) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | +| [monitoring_config](variables.tf#L292) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | +| [node_config](variables.tf#L371) | Node-level configuration. | object({…}) | | {} | +| [node_locations](variables.tf#L381) | Zones in which the cluster's nodes are located. | list(string) | | [] | +| [private_cluster_config](variables.tf#L388) | Private cluster configuration. | object({…}) | | null | +| [release_channel](variables.tf#L407) | 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 f0d2dcae5c..1b7fa41461 100644 --- a/modules/gke-cluster-standard/main.tf +++ b/modules/gke-cluster-standard/main.tf @@ -39,8 +39,8 @@ resource "google_container_cluster" "cluster" { enable_shielded_nodes = var.enable_features.shielded_nodes enable_fqdn_network_policy = var.enable_features.fqdn_network_policy enable_tpu = var.enable_features.tpu - initial_node_count = 1 - remove_default_node_pool = true + initial_node_count = var.default_node_pool.initial_node_count + remove_default_node_pool = var.default_node_pool.remove_pool deletion_protection = var.deletion_protection datapath_provider = ( var.enable_features.dataplane_v2 diff --git a/modules/gke-cluster-standard/variables.tf b/modules/gke-cluster-standard/variables.tf index 7a65571aa0..6a52e85d1a 100644 --- a/modules/gke-cluster-standard/variables.tf +++ b/modules/gke-cluster-standard/variables.tf @@ -113,6 +113,23 @@ variable "cluster_autoscaling" { } } +variable "default_node_pool" { + description = "Enable default node-pool." + type = object({ + remove_pool = optional(bool, true) + initial_node_count = optional(number, null) + }) + default = { + remove_pool = true + initial_node_count = null + } + + validation { + condition = ((var.default_node_pool.remove_pool == true && var.default_node_pool.initial_node_count == null) || (var.default_node_pool.remove_pool == false && var.default_node_pool.initial_node_count != null)) + error_message = "If `remove_pool` is set to false, `initial_node_count` need be set." + } +} + variable "deletion_protection" { description = "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." type = bool