我在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需要一个String而不是列表。 如何将列表转换为String才能得到这样的结果:
"IpAddress": {
"aws:SourceIp": [
"x.x.x.x/x",
"x.x.x.x/x"
]
}
答案 0 :(得分:2)
您可以在此处使用jsonencode
function:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "${jsonencode(source_ip)}"
}
}
}
]
}
答案 1 :(得分:1)
尝试
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<rsweb:ReportViewer ID="ReportViewer1" runat="server"
LocalReport="">
</rsweb:ReportViewer>
</div>
</form>
</body>
</html>
请注意,"aws:SourceIp": ["${join(", ", source_ip)}"]
在插值值之外,无法在策略中定义列表,但不表示Terraoform "[" and "]"
类型。
编辑:修正了以下注释中提到的错字。