From 22cb2e85b790be5777313cdc4d366d52ba2412af Mon Sep 17 00:00:00 2001 From: Piyush Kumar Sahu Date: Thu, 24 Jul 2025 11:46:30 +0530 Subject: [PATCH 1/2] added validation for metrics_filter --- variables.tf | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 605a35c5..2de4c066 100644 --- a/variables.tf +++ b/variables.tf @@ -263,7 +263,17 @@ variable "metrics_filter" { })) description = "To filter custom metrics you can specify which metrics to include and exclude. For more info, see https://cloud.ibm.com/docs/monitoring?topic=monitoring-change_kube_agent#change_kube_agent_inc_exc_metrics" default = [] - # TODO: Add variable validation to ensure only include or exclude is in each item - not both + validation { + condition = alltrue([ + for item in var.metrics_filter : ( + ( + (!(try(item.include, null) != null && try(item.exclude, null) != null)) && + ((try(item.include, null) != null && try(item.include, "") != "") || (try(item.exclude, null) != null && try(item.exclude, "") != "")) + ) + ) + ]) + error_message = "Each item in 'metrics_filter' must have either 'include' or 'exclude' set (not both, not neither), and the value must not be null or empty." + } } variable "container_filter" { From e5c81cd4493389ea575fd7eab9edd339073855e0 Mon Sep 17 00:00:00 2001 From: Piyush Kumar Sahu Date: Wed, 30 Jul 2025 14:50:15 +0530 Subject: [PATCH 2/2] Updated the error message --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 4d43d15d..2c9699f6 100644 --- a/variables.tf +++ b/variables.tf @@ -272,7 +272,7 @@ variable "metrics_filter" { ) ) ]) - error_message = "Each item in 'metrics_filter' must have either 'include' or 'exclude' set (not both, not neither), and the value must not be null or empty." + error_message = "Each metrics_filter item must specify exactly one of 'include' or 'exclude' with a non-empty value. Empty lists [] are allowed." } }