我试图将我的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将块更改为use
variable "postgres_dbs" {
type = map(string)但是运行terraform validate时的错误是:
This default value is not compatible with the variable's type constraint:
element "postgres6": string required.有什么建议吗?谢谢!
发布于 2020-10-20 03:04:57
您可以更新和微调您的类型规范,如下所示:
type = map(object({
name_postfix = string
enable = bool
sku = string
capacity = string
}))理想情况下,您可以将capacity对象参数指定为number,但是您将该参数的输入转换为string,因此这将导致不兼容,除非您将输入指定为其自然的number类型。
https://stackoverflow.com/questions/64430064
复制相似问题