Terraform 地形:在';对于';表达
我有一个数据文件site24x7IPs.json,它如下所示: 下面是我的terraform main.tf的一部分Terraform 地形:在';对于';表达,terraform,Terraform,我有一个数据文件site24x7IPs.json,它如下所示: 下面是我的terraform main.tf的一部分 本地人{ site24x7IPs=jsondecode(文件(“${path.module}/site24x7IPs.json”)) } 当地人{ ipList=[对于i in local.site24x7IPs.location详细信息:i.external_ip if i.Place==“Australia”] cidrList=[对于local.ipList中的j:leng
本地人{
site24x7IPs=jsondecode(文件(“${path.module}/site24x7IPs.json”))
}
当地人{
ipList=[对于i in local.site24x7IPs.location详细信息:i.external_ip if i.Place==“Australia”]
cidrList=[对于local.ipList中的j:length(regexall(“/”,j))更新:
正确的语法是:
cidrList = [ for j in local.ipList:
length(regexall("/", j)) <= 0 ? "${j}/32" : j ]
这将使:
[
{
"103.77.234.74/32" = "103.77.234.74"
},
]
或
谢谢Marci。我发现很多帖子都是关于循环支持的?:,我像上面那样尝试过,但都没有成功。我的terraform版本:terraform v0.13。4@user2920375我用正确的语法更新了答案。
cidrList = [ for j in local.ipList:
length(regexall("/", j)) <= 0 ? "${j}/32" : j ]
cidrList = [ for j in local.ipList:
{"${j}/32" : j } if length(regexall("/", j)) <= 0 ]
[
{
"103.77.234.74/32" = "103.77.234.74"
},
]
cidrList = [ for j in local.ipList:
"${j}/32" if length(regexall("/", j)) <= 0 ]
[
"103.77.234.74/32",
]