Skip to content

Commit 28b8107

Browse files
authored
fix: add validation for metrics_filter variable (#158)
1 parent f528eaf commit 28b8107

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 metrics_filter item must specify exactly one of 'include' or 'exclude' with a non-empty value. Empty lists [] are allowed."
276+
}
267277
}
268278

269279
variable "container_filter" {

0 commit comments

Comments
 (0)