Loops 验证terraform中的输入变量列表

Loops 验证terraform中的输入变量列表,loops,iterator,terraform,Loops,Iterator,Terraform,此验证块适用于单个输入变量 variable "mytestname" { validation { condition = length(regexall("test$", var.mytestname)) > 0 error_message = "Should end in test" } } 我需要它在for_中工作,或者有一些解决方法来完成这一点。问题在于条件语句有一个限制-条件必须接受输入变量本身(即-它不能接受each.v

此验证块适用于单个输入变量

variable "mytestname" {

     validation {
        condition = length(regexall("test$", var.mytestname)) > 0
        error_message = "Should end in test"
     }
}
我需要它在for_中工作,或者有一些解决方法来完成这一点。问题在于条件语句有一个限制-条件必须接受输入变量本身(即-它不能接受each.value)


上面的代码段不起作用。我需要一种方法,我可以迭代一个值列表,并验证每个值。看起来新引入的“验证块”对输入变量列表不起作用。必须有一种方法可以在没有验证块的情况下完成此操作…?

我相信它不会起作用。可以在变量块中定义的属性有类型、描述和默认值。那么,我们如何动态定义其他属性,如“listnames”

variable "mytestnames" {
    listnames = split(",",var.mytestnames)
}

是的,你是对的。正确的块是terraform{experiments=[variable\u validation]}variable“list names”{type=list default=[“example.com”,“www.example.com”]validation{condition=length(regexall(“mytest.com$”,var.list-names[0])>0 error\u message=“应该以mytest.com结尾。”}
variable "mytestnames" {
    listnames = split(",",var.mytestnames)
}
$ terraform validate

Error: Unsupported argument

  on hoge.tf line 3, in variable "mytestnames":
   3: listnames = split(",",var.mytestnames)

An argument named "listnames" is not expected here.