From acaac300aef152b12b46847b6e25718d04f16724 Mon Sep 17 00:00:00 2001 From: Federico Preli <73168935+fpreli@users.noreply.github.com> Date: Mon, 17 Mar 2025 17:41:48 +0100 Subject: [PATCH] Adding enterprise_config -> desired_tier feature to GKE autopilot and standard (#2962) Add --- modules/gke-cluster-autopilot/README.md | 28 ++++++++++---------- modules/gke-cluster-autopilot/main.tf | 6 +++++ modules/gke-cluster-autopilot/variables.tf | 1 + modules/gke-cluster-standard/README.md | 30 +++++++++++----------- modules/gke-cluster-standard/main.tf | 6 +++++ modules/gke-cluster-standard/variables.tf | 1 + 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/modules/gke-cluster-autopilot/README.md b/modules/gke-cluster-autopilot/README.md index 0cb99a279..5fb61ee9b 100644 --- a/modules/gke-cluster-autopilot/README.md +++ b/modules/gke-cluster-autopilot/README.md @@ -205,25 +205,25 @@ module "cluster-1" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [location](variables.tf#L143) | Autopilot clusters are always regional. | string | ✓ | | -| [name](variables.tf#L222) | Cluster name. | string | ✓ | | -| [project_id](variables.tf#L253) | Cluster project ID. | string | ✓ | | -| [vpc_config](variables.tf#L269) | VPC-level configuration. | object({…}) | ✓ | | +| [location](variables.tf#L144) | Autopilot clusters are always regional. | string | ✓ | | +| [name](variables.tf#L223) | Cluster name. | string | ✓ | | +| [project_id](variables.tf#L254) | Cluster project ID. | string | ✓ | | +| [vpc_config](variables.tf#L270) | VPC-level configuration. | object({…}) | ✓ | | | [access_config](variables.tf#L17) | Control plane endpoint and nodes access configurations. | object({…}) | | {} | | [backup_configs](variables.tf#L42) | Configuration for Backup for GKE. | object({…}) | | {} | | [deletion_protection](variables.tf#L63) | 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#L70) | Cluster description. | string | | null | | [enable_addons](variables.tf#L76) | Addons enabled in the cluster (true means enabled). | object({…}) | | {} | -| [enable_features](variables.tf#L90) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {} | -| [issue_client_certificate](variables.tf#L131) | Enable issuing client certificate. | bool | | false | -| [labels](variables.tf#L137) | Cluster resource labels. | map(string) | | null | -| [logging_config](variables.tf#L148) | Logging configuration. | object({…}) | | {} | -| [maintenance_config](variables.tf#L159) | Maintenance window configuration. | object({…}) | | {…} | -| [min_master_version](variables.tf#L182) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | -| [monitoring_config](variables.tf#L188) | Monitoring configuration. System metrics collection cannot be disabled. Control plane metrics are optional. Kube state metrics are optional. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | -| [node_config](variables.tf#L227) | Configuration for nodes and nodepools. | object({…}) | | {} | -| [node_locations](variables.tf#L246) | Zones in which the cluster's nodes are located. | list(string) | | [] | -| [release_channel](variables.tf#L258) | Release channel for GKE upgrades. Clusters created in the Autopilot mode must use a release channel. Choose between \"RAPID\", \"REGULAR\", and \"STABLE\". | string | | "REGULAR" | +| [enable_features](variables.tf#L90) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {} | +| [issue_client_certificate](variables.tf#L132) | Enable issuing client certificate. | bool | | false | +| [labels](variables.tf#L138) | Cluster resource labels. | map(string) | | null | +| [logging_config](variables.tf#L149) | Logging configuration. | object({…}) | | {} | +| [maintenance_config](variables.tf#L160) | Maintenance window configuration. | object({…}) | | {…} | +| [min_master_version](variables.tf#L183) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | +| [monitoring_config](variables.tf#L189) | Monitoring configuration. System metrics collection cannot be disabled. Control plane metrics are optional. Kube state metrics are optional. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | +| [node_config](variables.tf#L228) | Configuration for nodes and nodepools. | object({…}) | | {} | +| [node_locations](variables.tf#L247) | Zones in which the cluster's nodes are located. | list(string) | | [] | +| [release_channel](variables.tf#L259) | Release channel for GKE upgrades. Clusters created in the Autopilot mode must use a release channel. Choose between \"RAPID\", \"REGULAR\", and \"STABLE\". | string | | "REGULAR" | ## Outputs diff --git a/modules/gke-cluster-autopilot/main.tf b/modules/gke-cluster-autopilot/main.tf index 54259b704..8a60908f5 100644 --- a/modules/gke-cluster-autopilot/main.tf +++ b/modules/gke-cluster-autopilot/main.tf @@ -339,6 +339,12 @@ resource "google_container_cluster" "cluster" { enabled = var.enable_features.vertical_pod_autoscaling } } + dynamic "enterprise_config" { + for_each = var.enable_features.enterprise_cluster != null ? [""] : [] + content { + desired_tier = var.enable_features.enterprise_cluster ? "ENTERPRISE" : "STANDARD" + } + } } resource "google_gke_backup_backup_plan" "backup_plan" { diff --git a/modules/gke-cluster-autopilot/variables.tf b/modules/gke-cluster-autopilot/variables.tf index c5e96fa01..000496e8a 100644 --- a/modules/gke-cluster-autopilot/variables.tf +++ b/modules/gke-cluster-autopilot/variables.tf @@ -124,6 +124,7 @@ variable "enable_features" { topic_id = optional(string) })) vertical_pod_autoscaling = optional(bool, false) + enterprise_cluster = optional(bool) }) default = {} } diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md index 618e67936..e6dbd08b3 100644 --- a/modules/gke-cluster-standard/README.md +++ b/modules/gke-cluster-standard/README.md @@ -428,10 +428,10 @@ module "cluster-1" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [location](variables.tf#L262) | Cluster zone or region. | string | ✓ | | -| [name](variables.tf#L377) | Cluster name. | string | ✓ | | -| [project_id](variables.tf#L410) | Cluster project id. | string | ✓ | | -| [vpc_config](variables.tf#L421) | VPC-level configuration. | object({…}) | ✓ | | +| [location](variables.tf#L263) | Cluster zone or region. | string | ✓ | | +| [name](variables.tf#L378) | Cluster name. | string | ✓ | | +| [project_id](variables.tf#L411) | Cluster project id. | string | ✓ | | +| [vpc_config](variables.tf#L422) | VPC-level configuration. | object({…}) | ✓ | | | [access_config](variables.tf#L17) | Control plane endpoint and nodes access configurations. | object({…}) | | {} | | [backup_configs](variables.tf#L42) | Configuration for Backup for GKE. | object({…}) | | {} | | [cluster_autoscaling](variables.tf#L64) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…}) | | null | @@ -439,17 +439,17 @@ module "cluster-1" { | [deletion_protection](variables.tf#L161) | 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#L168) | Cluster description. | string | | null | | [enable_addons](variables.tf#L174) | Addons enabled in the cluster (true means enabled). | object({…}) | | {} | -| [enable_features](variables.tf#L196) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {} | -| [issue_client_certificate](variables.tf#L249) | Enable issuing client certificate. | bool | | false | -| [labels](variables.tf#L255) | Cluster resource labels. | map(string) | | {} | -| [logging_config](variables.tf#L267) | Logging configuration. | object({…}) | | {} | -| [maintenance_config](variables.tf#L288) | Maintenance window configuration. | object({…}) | | {…} | -| [max_pods_per_node](variables.tf#L311) | Maximum number of pods per node in this cluster. | number | | 110 | -| [min_master_version](variables.tf#L317) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | -| [monitoring_config](variables.tf#L323) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | -| [node_config](variables.tf#L382) | Node-level configuration. | object({…}) | | {} | -| [node_locations](variables.tf#L403) | Zones in which the cluster's nodes are located. | list(string) | | [] | -| [release_channel](variables.tf#L415) | Release channel for GKE upgrades. | string | | null | +| [enable_features](variables.tf#L196) | Enable cluster-level features. Certain features allow configuration. | object({…}) | | {} | +| [issue_client_certificate](variables.tf#L250) | Enable issuing client certificate. | bool | | false | +| [labels](variables.tf#L256) | Cluster resource labels. | map(string) | | {} | +| [logging_config](variables.tf#L268) | Logging configuration. | object({…}) | | {} | +| [maintenance_config](variables.tf#L289) | Maintenance window configuration. | object({…}) | | {…} | +| [max_pods_per_node](variables.tf#L312) | Maximum number of pods per node in this cluster. | number | | 110 | +| [min_master_version](variables.tf#L318) | Minimum version of the master, defaults to the version of the most recent official release. | string | | null | +| [monitoring_config](variables.tf#L324) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | +| [node_config](variables.tf#L383) | Node-level configuration. | object({…}) | | {} | +| [node_locations](variables.tf#L404) | Zones in which the cluster's nodes are located. | list(string) | | [] | +| [release_channel](variables.tf#L416) | 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 73c5bc112..eaa50464e 100644 --- a/modules/gke-cluster-standard/main.tf +++ b/modules/gke-cluster-standard/main.tf @@ -552,6 +552,12 @@ resource "google_container_cluster" "cluster" { workload_pool = "${var.project_id}.svc.id.goog" } } + dynamic "enterprise_config" { + for_each = var.enable_features.enterprise_cluster != null ? [""] : [] + content { + desired_tier = var.enable_features.enterprise_cluster ? "ENTERPRISE" : "STANDARD" + } + } lifecycle { ignore_changes = [node_config] } diff --git a/modules/gke-cluster-standard/variables.tf b/modules/gke-cluster-standard/variables.tf index 27ec46b21..ee2f7d8e7 100644 --- a/modules/gke-cluster-standard/variables.tf +++ b/modules/gke-cluster-standard/variables.tf @@ -236,6 +236,7 @@ variable "enable_features" { })) vertical_pod_autoscaling = optional(bool, false) workload_identity = optional(bool, true) + enterprise_cluster = optional(bool) }) default = {} validation {