diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md index ef61ea47..acc8f551 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#L229) | Cluster zone or region. | string | ✓ | | +| [name](variables.tf#L364) | Cluster name. | string | ✓ | | +| [project_id](variables.tf#L400) | Cluster project id. | string | ✓ | | +| [vpc_config](variables.tf#L411) | 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#L131) | 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#L138) | Cluster description. | string | | null | +| [enable_addons](variables.tf#L144) | Addons enabled in the cluster (true means enabled). | object({…}) | | {…} | +| [enable_features](variables.tf#L168) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {…} | +| [issue_client_certificate](variables.tf#L217) | Enable issuing client certificate. | bool | | false | +| [labels](variables.tf#L223) | Cluster resource labels. | map(string) | | null | +| [logging_config](variables.tf#L234) | Logging configuration. | object({…}) | | {} | +| [maintenance_config](variables.tf#L255) | Maintenance window configuration. | object({…}) | | {…} | +| [max_pods_per_node](variables.tf#L278) | Maximum number of pods per node in this cluster. | number | | 110 | +| [min_master_version](variables.tf#L284) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | +| [monitoring_config](variables.tf#L290) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | +| [node_config](variables.tf#L369) | Node-level configuration. | object({…}) | | {} | +| [node_locations](variables.tf#L379) | Zones in which the cluster's nodes are located. | list(string) | | [] | +| [private_cluster_config](variables.tf#L386) | Private cluster configuration. | object({…}) | | null | +| [release_channel](variables.tf#L405) | 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 f0d2dcae..1b7fa414 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 7a65571a..122da653 100644 --- a/modules/gke-cluster-standard/variables.tf +++ b/modules/gke-cluster-standard/variables.tf @@ -113,6 +113,21 @@ variable "cluster_autoscaling" { } } +variable "default_node_pool" { + description = "Enable default node-pool." + type = object({ + remove_pool = optional(bool, true) + initial_node_count = optional(number) + }) + default = {} + nullable = false + + validation { + condition = (var.default_node_pool.remove_pool != (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 diff --git a/tests/modules/gke_hub/examples/full.yaml b/tests/modules/gke_hub/examples/full.yaml index 9572e071..d00571c1 100644 --- a/tests/modules/gke_hub/examples/full.yaml +++ b/tests/modules/gke_hub/examples/full.yaml @@ -59,7 +59,7 @@ values: enable_shielded_nodes: false enable_tpu: false fleet: [] - initial_node_count: 1 + initial_node_count: null location: europe-west1 logging_config: - enable_components: