对象默认值的Terraform列表



当我试图为列表中的对象设置默认值时,遇到了一个错误:

variable "routes" {
type = list(object({
destination_cidr_block = string
blackhole = bool})
default = {
blackhole = "false"
destination_cidr_block = ""
})
description = "a list of objects containing the cidr blocks of the dest and whether the cidr is a blackhole or not."
default = null
}

当我运行这个时,我得到以下错误:

Error: Missing argument separator
on variables.tf line 21, in variable "routes":
18:   type = list(object({
19:     destination_cidr_block = string
20:     blackhole = bool})
21:     default = {
A comma is required to separate each function argument from the next.

第21行";默认";错误中有下划线。

当它本身只是一个对象时,以这种方式设置默认值很好。我不知道当变量是一个对象列表时,它为什么会抱怨。

您可能想要这样的:

variable "routes" {
type = list(object({
destination_cidr_block = string
blackhole              = bool
}))
default = [{
blackhole              = "false"
destination_cidr_block = ""
}]
description = "a list of objects containing the cidr blocks of the dest and whether the cidr is a blackhole or not."
}

类型中不可能真正包含default

我请求了一个对象类型默认功能,他们现在正在将对象类型约束的可选属性发布到Terraform的下一个构建中!