【发布时间】:2021-09-23 17:10:40
【问题描述】:
我的 main.tf 下面有一个示例。 出于某种原因,它强制模板变量上的双引号在我的模板文件中环绕,而来自其他来源的示例使用下面没有引号环绕:
%{ for i in split(",",mylist) ~}
Here's a value: ${i}
%{ endfor }
我的语法在文件上没有显示错误,但在运行时会出错 "%{ for addr in split(",",source_vpcs) ~} ${addr} %{ endfor ~}"
我收到此错误: 无效的功能 争论; “str”参数的值无效:需要字符串..
如何正确使用列表? source_vpcs = ["vpc1212","vpc21"]
#i am trying to pass this from the main.tf to pass into aws_vpc_endpoint resource and into its policy attribute.
policy = templatefile("../templates/access_polices.tmpl",
{
s3env = "dev"
account_num = "8888888"
source_vpcs = local.source_vpcs
}
)
这是一个 tmpl 文件 ####新内容###
${jsonencode(
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "xx",
"Effect": "Deny",
"Action": [
"s3:GetObject"
],
"Resource": [
"*"
],
"Condition": {
"StringNotEquals": {
"aws:SourceVpc": "${source_vpcs}",
"s3:ResourceAccount": "${account_number}"
}
}
},
]
}
)}
这是我想要实现的示例输出
"Condition": {
"StringNotEquals": {
"aws:SourceVpc":
[
"vpc-888888888f",
"vpc-999999999f"
]
,
"s3:ResourceAccount":
[
888888888
]
}
【问题讨论】:
-
Terraform 每两秒发布一次新版本 :D,如果您可以提供您使用的 terraform 版本,可以帮助其他人回答您的问题。
-
我还在 tmpl 文件上尝试了 jsonencode 函数 ${jsonencode(policy)} 并且我能够做一个 terraform 计划,好像它看起来不错但是当我应用它时它并没有看到它有效的政策。我已经检查了政策是否正确。
-
嗨 Vidura,我正在使用 Terraform v0.13.4
标签: amazon-web-services terraform-provider-aws terraform-template-file