从terraform中的csv构建地图列表
我有以下变量从terraform中的csv构建地图列表,terraform,Terraform,我有以下变量 variable "whitelisted_ips" { default = "xx.xxx.xx.x/21,xxx.xx.xxx.x/20" } 我在一些需要苹果酒列表的地方使用它,使用如下 cidr_blocks = ["${split(",", var.whitelisted_ips)}"] 一切正常 我希望重用这些值,并最终得到以下结构(表示为JSON,让您了解情况) 因此,我希望从字符串中创建一个映射列表(IPV4是硬编码的,并且在每一行上重复) 如果我
variable "whitelisted_ips" {
default = "xx.xxx.xx.x/21,xxx.xx.xxx.x/20"
}
我在一些需要苹果酒列表的地方使用它,使用如下
cidr_blocks = ["${split(",", var.whitelisted_ips)}"]
一切正常
我希望重用这些值,并最终得到以下结构(表示为JSON,让您了解情况)
因此,我希望从字符串中创建一个映射列表(IPV4是硬编码的,并且在每一行上重复)
如果我将当前的JSON提供给aws_waf_规则并将其视为一个列表,则会成功,但我不希望重复tfvars文件中的数据,因为它们是相同的,我希望重用该字符串分隔的列表。好吧,了解了更多内容并阅读了更多内容,结果表明,您可以使用空资源来处理静态数据
locals {
cidr_blocks = ["xxx.xxx.xxx/23", "xxx.xxx.xxx/23", "xxx.xxx.xxx/23"]
}
resource "null_resource" "cidr_map_to_protocol" {
count = "${length(local.cidr_blocks)}"
triggers {
value = "${element(local.cidr_blocks, count.index)}"
type = "IPV4"
}
}
output "mapped_cidr_to_protocol" {
value = "${null_resource.cidr_map_to_protocol.*.triggers}"
}
不幸的是,这对计算资源不起作用
locals {
cidr_blocks = ["xxx.xxx.xxx/23", "xxx.xxx.xxx/23", "xxx.xxx.xxx/23"]
}
resource "null_resource" "cidr_map_to_protocol" {
count = "${length(local.cidr_blocks)}"
triggers {
value = "${element(local.cidr_blocks, count.index)}"
type = "IPV4"
}
}
output "mapped_cidr_to_protocol" {
value = "${null_resource.cidr_map_to_protocol.*.triggers}"
}