【发布时间】:2021-02-02 09:22:14
【问题描述】:
我正在尝试将我的 TF 0.11 代码升级到 0.12,但遇到了一个变量问题。
在 TF 0.11 中,此阻塞在 variables.tf 文件中按预期工作
variable "postgres_dbs" {
type = "map"
default = {
postgres1 = {
name_postfix = "postgres",
enable = true,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres2 = {
name_postfix = "postgres-2",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres3 = {
name_postfix = "postgres-3",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres4 = {
name_postfix = "postgres-4",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres5 = {
name_postfix = "postgres-5",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres6 = {
name_postfix = "postgres-6",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres7 = {
name_postfix = "postgres-7",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
postgres8 = {
name_postfix = "postgres-8",
enable = false,
sku = "MO_Gen5_16",
capacity = "16"
}
}
}
运行 terraform 012upgrade 命令后(它没有错误完成) TF改块使用
variable "postgres_dbs" {
type = map(string)
但是运行 terraform validate 时的错误是:
This default value is not compatible with the variable's type constraint:
element "postgres6": string required.
有什么建议吗? 谢谢!
【问题讨论】:
-
你能试试把
map(string)改成map(map)吗? -
尝试并得到此错误:144:type = map(map) 地图类型构造函数需要一个参数来指定元素类型。
-
看起来实际上是
map(object)。
标签: terraform