This validation block works for a single input variable.
variable "mytestname" {
validation {
condition = length(regexall("^test", var.mytestname)) > 0
error_message = "Should start with 'test'"
}
}
I need it to work inside a for_each - or have some workaround to accomplish this. The issue is that there is a restriction on the condition statement - the condition HAS to take in the input variable itself (i.e. - it cannot accept an each.value)
variable "mytestnames" {
listnames = split(",",var.mytestnames)
for_each = var.listnames
validation {
condition = length(regexall("^test", each.value)) > 0
error_message = "Should start with test"
}
}
The above snippet does not work. I need a way I can iterate over a list of values and validate each of them using the validation block.