Terraform v0.10.7 AWS提供的版本= “〜> 1.54.0”
是否有任何的例子如何将一个字符串或列表进入Terraform地图吗?
我们正在建立领事键/值存储这样的:
consul kv put common/rules/alb/service1 name=service1,port=80,hcproto=http,hcport=80
我可以访问键和值正常,现在我想使用值作为Terraform地图:
data "consul_key_prefix" "common" {
path_prefix = "common/rules"
}
output "common"{
value = "${jsonencode(lookup(var.CommonRules,element(keys(var.CommonRules),1))) }"
}
$ terraform输出
common = "{name=service1,port=80,hcproto=http,hcport=80}"
但是,当我尝试访问它作为一个地图,这是行不通的:
output "common"{
value = "${lookup(jsonencode(lookup(var.CommonRules,element(keys(var.CommonRules),1))),"name") }"
}
$ terraform输出
(没有反应)
我尝试一些东西在这里 - 例如拆分这些值,并再次将它们连接成一个列表,然后运行“映射”功能,但它不工作之一:
$ terraform输出
common = [
name,
service1,
port,
80,
hcproto,
http,
hcport,
80
]
然后试图创建列表的图:
output "common2" {
value = "${map(split(",",join(",",split("=",lookup(var.CommonRules,element(keys(var.CommonRules),1))))))}"
}
但它并不能工作。
所以,我的问题是 - 没有任何人有工作示例,其中他翻译的字符串(或清单)到地图吗?
提前致谢。
在即将到来的Terraform jsondecode
功能v0.12
将是解决这一问题的工具。