当为addresses在Terraform中创建aws_waf_ipsets时,我有多个IP地址列表,我想在创建aws_waf_rule时将它们连接在一起。当我尝试在concat的data_id中使用aws_waf_rule时,会得到一个错误:* aws_waf_rule.production_wafrule: predicates.0.data_id must be a single value, not a list。
这对我来说是有意义的,但是如果我不能在aws_waf_rule中直接连接它,我如何最好地创建一个连接列表,作为我可以在数据ID中引用的资源呢?
下面是生成此错误的示例代码:
resource "aws_waf_rule" "production_wafrule" {
name = "production_WAF_rule"
metric_name = "ProductionWAFRule"
predicates {
data_id = "${concat(list(aws_waf_ipset.vpn_ipset.id),list(aws_waf_ipset.production_ipset.id))}"
negated = false
type = "IPMatch"
}
}发布于 2019-09-02 17:44:46
flatten() (https://www.terraform.io/docs/configuration/functions/flatten.html)可能就是你要找的东西。
没有测试,但是类似这样的内容应该可以完成(请注意,该函数只接受一个列表作为输入,您可以将所有列表放入其中)-
"${flatten([list(aws_waf_ipset.vpn_ipset.id),list(aws_waf_ipset.production_ipset.id)])}"我相信setunion() (https://www.terraform.io/docs/configuration/functions/setunion.html)也会在列表上工作(并且会减少任何重复的项目)。
https://serverfault.com/questions/978374
复制相似问题