【发布时间】:2019-06-24 21:57:56
【问题描述】:
我在 Terraform 中有这个政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "${source_ip}"
}
}
}
]
}
我有一个如下定义的变量 authorized_ip:
variable "authorized_ip" {
default = [
"x.x.x.x/x",
"x.x.x.x/x",
]
}
现在我这样调用 Json 策略:
data "template_file" "apigw_policy" {
template = "${file("${path.module}/template/apigateway_policy.json.template")}"
vars = {
source_ip = "${var.authorized_ip}"
}
}
但是我收到了这个错误:
属性“vars”的值不合适:元素“source_ip”:字符串 必填。
所以 Terraform 需要一个字符串而不是列表。 如何将列表转换为字符串以获得这样的结果:
"IpAddress": {
"aws:SourceIp": [
"x.x.x.x/x",
"x.x.x.x/x"
]
}
【问题讨论】:
-
根据discuss.hashicorp.com/t/inappropriate-value-for-attribute-vars/…,
template_file数据源已弃用且不接受列表变量。使用templatefile函数以及下面的@ydaetskcoR 答案
标签: amazon-web-services terraform