转换
variable
到
local
所以它可以使用其他局部变量是正确的解决方案。使用terraform 0.12。x以下工程如业主所预期:
terraform apply
.
locals {
cool_style = {
palette = "cool"
type = "solid"
width = "normal"
}
orange_style = {
palette = "orange"
type = "solid"
width = "normal"
}
query_timeseries = [
{
q = "avg:xx.xxxx{xxx:xx}"
type = "bars"
style = local.cool_style
},
{
q = "avg:xx.xxxx{xxx:xx}"
type = "bars"
style = local.orange_style
}
]
}
output "query_timeseries" {
value = local.query_timeseries
}
$ terraform init
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
query_timeseries = [
{
"q" = "avg:xx.xxxx{xxx:xx}"
"style" = {
"palette" = "cool"
"type" = "solid"
"width" = "normal"
}
"type" = "bars"
},
{
"q" = "avg:xx.xxxx{xxx:xx}"
"style" = {
"palette" = "orange"
"type" = "solid"
"width" = "normal"
}
"type" = "bars"
},
]