Skip to content

Commit f6792c8

Browse files
committed
feat: add validation to monitoring_enabled_components and logging_enabled_components
1 parent c07c05b commit f6792c8

File tree

20 files changed

+357
-25
lines changed

20 files changed

+357
-25
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ resource "google_container_cluster" "primary" {
9494
}
9595
}
9696
{% endif %}
97-
9897
dynamic "logging_config" {
9998
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
10099

@@ -134,7 +133,6 @@ resource "google_container_cluster" "primary" {
134133
{% else %}
135134
logging_service = local.logmon_config_is_set ? null : var.logging_service
136135
{% endif %}
137-
138136
{% if beta_cluster %}
139137
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
140138
{% else %}

autogen/main/variables.tf.tmpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,47 @@ variable "monitoring_enabled_components" {
856856
type = list(string)
857857
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
858858
default = []
859+
validation {
860+
condition = alltrue([
861+
for c in var.monitoring_enabled_components:
862+
contains([
863+
"SYSTEM_COMPONENTS",
864+
"APISERVER",
865+
"SCHEDULER",
866+
"CONTROLLER_MANAGER",
867+
"STORAGE",
868+
"HPA",
869+
"POD",
870+
"DAEMONSET",
871+
"DEPLOYMENT",
872+
"STATEFULSET",
873+
"WORKLOADS",
874+
"KUBELET",
875+
"CADVISOR",
876+
"DCGM"
877+
], c)
878+
])
879+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
880+
}
859881
}
860882

861883
variable "logging_enabled_components" {
862884
type = list(string)
863885
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
864886
default = []
887+
validation {
888+
condition = alltrue([
889+
for c in var.logging_enabled_components:
890+
contains([
891+
"SYSTEM_COMPONENTS",
892+
"APISERVER",
893+
"CONTROLLER_MANAGER",
894+
"SCHEDULER",
895+
"WORKLOADS"
896+
], c)
897+
])
898+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
899+
}
865900
}
866901

867902
{% if autopilot_cluster != true %}

cluster.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ resource "google_container_cluster" "primary" {
8080

8181
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
8282

83-
8483
dynamic "logging_config" {
8584
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
8685

@@ -104,8 +103,7 @@ resource "google_container_cluster" "primary" {
104103
}
105104

106105
# only one of logging/monitoring_service or logging/monitoring_config can be specified
107-
logging_service = local.logmon_config_is_set ? null : var.logging_service
108-
106+
logging_service = local.logmon_config_is_set ? null : var.logging_service
109107
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
110108

111109
cluster_autoscaling {

modules/beta-autopilot-private-cluster/cluster.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ resource "google_container_cluster" "primary" {
7272

7373
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7474

75-
7675
dynamic "logging_config" {
7776
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
7877

modules/beta-autopilot-private-cluster/variables.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,47 @@ variable "monitoring_enabled_components" {
523523
type = list(string)
524524
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
525525
default = []
526+
validation {
527+
condition = alltrue([
528+
for c in var.monitoring_enabled_components :
529+
contains([
530+
"SYSTEM_COMPONENTS",
531+
"APISERVER",
532+
"SCHEDULER",
533+
"CONTROLLER_MANAGER",
534+
"STORAGE",
535+
"HPA",
536+
"POD",
537+
"DAEMONSET",
538+
"DEPLOYMENT",
539+
"STATEFULSET",
540+
"WORKLOADS",
541+
"KUBELET",
542+
"CADVISOR",
543+
"DCGM"
544+
], c)
545+
])
546+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
547+
}
526548
}
527549

528550
variable "logging_enabled_components" {
529551
type = list(string)
530552
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
531553
default = []
554+
validation {
555+
condition = alltrue([
556+
for c in var.logging_enabled_components :
557+
contains([
558+
"SYSTEM_COMPONENTS",
559+
"APISERVER",
560+
"CONTROLLER_MANAGER",
561+
"SCHEDULER",
562+
"WORKLOADS"
563+
], c)
564+
])
565+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
566+
}
532567
}
533568

534569
variable "enable_l4_ilb_subsetting" {

modules/beta-autopilot-public-cluster/cluster.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ resource "google_container_cluster" "primary" {
7272

7373
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7474

75-
7675
dynamic "logging_config" {
7776
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
7877

modules/beta-autopilot-public-cluster/variables.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,47 @@ variable "monitoring_enabled_components" {
487487
type = list(string)
488488
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
489489
default = []
490+
validation {
491+
condition = alltrue([
492+
for c in var.monitoring_enabled_components :
493+
contains([
494+
"SYSTEM_COMPONENTS",
495+
"APISERVER",
496+
"SCHEDULER",
497+
"CONTROLLER_MANAGER",
498+
"STORAGE",
499+
"HPA",
500+
"POD",
501+
"DAEMONSET",
502+
"DEPLOYMENT",
503+
"STATEFULSET",
504+
"WORKLOADS",
505+
"KUBELET",
506+
"CADVISOR",
507+
"DCGM"
508+
], c)
509+
])
510+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
511+
}
490512
}
491513

492514
variable "logging_enabled_components" {
493515
type = list(string)
494516
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
495517
default = []
518+
validation {
519+
condition = alltrue([
520+
for c in var.logging_enabled_components :
521+
contains([
522+
"SYSTEM_COMPONENTS",
523+
"APISERVER",
524+
"CONTROLLER_MANAGER",
525+
"SCHEDULER",
526+
"WORKLOADS"
527+
], c)
528+
])
529+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
530+
}
496531
}
497532

498533
variable "enable_l4_ilb_subsetting" {

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ resource "google_container_cluster" "primary" {
8686
type = var.cluster_telemetry_type
8787
}
8888
}
89-
9089
dynamic "logging_config" {
9190
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
9291

@@ -110,8 +109,7 @@ resource "google_container_cluster" "primary" {
110109
}
111110

112111
# only one of logging/monitoring_service or logging/monitoring_config can be specified
113-
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
114-
112+
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
115113
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
116114

117115
cluster_autoscaling {

modules/beta-private-cluster-update-variant/variables.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,47 @@ variable "monitoring_enabled_components" {
816816
type = list(string)
817817
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
818818
default = []
819+
validation {
820+
condition = alltrue([
821+
for c in var.monitoring_enabled_components :
822+
contains([
823+
"SYSTEM_COMPONENTS",
824+
"APISERVER",
825+
"SCHEDULER",
826+
"CONTROLLER_MANAGER",
827+
"STORAGE",
828+
"HPA",
829+
"POD",
830+
"DAEMONSET",
831+
"DEPLOYMENT",
832+
"STATEFULSET",
833+
"WORKLOADS",
834+
"KUBELET",
835+
"CADVISOR",
836+
"DCGM"
837+
], c)
838+
])
839+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
840+
}
819841
}
820842

821843
variable "logging_enabled_components" {
822844
type = list(string)
823845
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
824846
default = []
847+
validation {
848+
condition = alltrue([
849+
for c in var.logging_enabled_components :
850+
contains([
851+
"SYSTEM_COMPONENTS",
852+
"APISERVER",
853+
"CONTROLLER_MANAGER",
854+
"SCHEDULER",
855+
"WORKLOADS"
856+
], c)
857+
])
858+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
859+
}
825860
}
826861

827862
variable "monitoring_enable_managed_prometheus" {

modules/beta-private-cluster/cluster.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ resource "google_container_cluster" "primary" {
8686
type = var.cluster_telemetry_type
8787
}
8888
}
89-
9089
dynamic "logging_config" {
9190
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
9291

@@ -110,8 +109,7 @@ resource "google_container_cluster" "primary" {
110109
}
111110

112111
# only one of logging/monitoring_service or logging/monitoring_config can be specified
113-
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
114-
112+
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
115113
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
116114

117115
cluster_autoscaling {

0 commit comments

Comments
 (0)