问题声明我试图用terraform 实现api网关的自动化是我的代码的一部分
为api网关
resource "aws_api_gateway_rest_api" "rest_api" {
#some code
policy = "${data.template_file.init.rendered}"
}
output "id" {
value = "${aws_api_gateway_rest_api.rest_api.id}"
}
output "execution_arn" {
value = "${aws_api_gateway_rest_api.rest_api.execution_arn}"
}
output "arn" {
value = "${aws_api_gateway_rest_api.rest_api.arn}"
}对于资源策略,请注意,我希望在json策略文档中自动插入api id。
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
data "template_file" "init" {
template = "${file("${path.root}/${var.policy_file_location}")}"
vars = {
current_region = "${data.aws_region.current.name}"
current_aws_account = "${data.aws_caller_identity.current.account_id}"
current_api_id = "${aws_api_gateway_rest_api.rest_api.id}"
}
}json政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:${current_region}:${current_aws_account}:${current_api_id}/*"
}
]
}当我试图提供与以下类似的资源策略时,我将得到
错误:循环: module.simple-api-gw.data.template_file.init,module.simple-api-gw.aws_api_gateway_rest_api.rest_api
如何解决此错误?我想在json文件中动态地提供api id。
发布于 2020-02-19 16:16:00
您正在生成的策略是适合分配给IAM角色或IAM用户,允许它们调用API。直接将特定策略分配给API是没有意义的。本质上,您说的是“任何拥有调用API权限的人都可以拥有调用API的权限”,这是一个循环语句。
策略适合于分配给API网关将对特定的主体或特定的IP地址执行类似的限制请求。
请参阅我上面所链接的文件。它概述了通过IAM权限或资源策略控制对API网关的访问的两种不同方法。您正在尝试将IAM权限分配为资源策略,这是行不通的。
发布于 2020-08-24 10:51:54
问题是,在创建资源时,您正在尝试引用资源的输出。您不需要为策略中的资源填充执行arn,而是使用“execute:/*”。
https://stackoverflow.com/questions/60302431
复制相似问题