Terraform variable validation using length function Getting error while using length function & substr for vswitch_ids Condition - vswitch_name value must start with vsw-
variable "vswitch_ids" {
description = "The vswitch IDs."
type = list(string)
validation {
condition = (
length(var.vswitch_ids) > 0 &&
substr(var.switch_ids, 0, 4) == "vsw-"
)
error_message = "The vswitch_name value must start with \"vsw-\"."
} }
Error: Invalid function argument
on modules/k8s/variables.tf line 34, in variable "vswitch_ids":
34: substr(var.vswitch_ids, 0, 4) == "vsw-"
|----------------
| var.vswitch_ids is list of string with 3 elements
Invalid value for "str" parameter: string required.
var.vswitch_idsis list, not string. What do you want to achieve? Your use ofsubstrdoes not make sense in your context.