Skip to content

Commit 22cb2e8

Browse files
Piyush Kumar SahuPiyush Kumar Sahu
authored andcommitted
added validation for metrics_filter
1 parent b3cd688 commit 22cb2e8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

variables.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,17 @@ variable "metrics_filter" {
263263
}))
264264
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"
265265
default = []
266-
# TODO: Add variable validation to ensure only include or exclude is in each item - not both
266+
validation {
267+
condition = alltrue([
268+
for item in var.metrics_filter : (
269+
(
270+
(!(try(item.include, null) != null && try(item.exclude, null) != null)) &&
271+
((try(item.include, null) != null && try(item.include, "") != "") || (try(item.exclude, null) != null && try(item.exclude, "") != ""))
272+
)
273+
)
274+
])
275+
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."
276+
}
267277
}
268278

269279
variable "container_filter" {

0 commit comments

Comments
 (0)