我能找到的唯一关于路径变量的信息是这篇stackoverflow文章:In Terraform, how do you specify an API Gateway endpoint with a variable in the request path?
在这个答案中,将路径变量指定在aws_api_gateway_integration函数的uri字段中:
resource "aws_api_gateway_integration" "get-account-integration" {
rest_api_id = "${var.gateway_id}"
resource_id = "${var.resource_id}"
http_method = "${aws_api_gateway_method.get-account.http_method}"
type = "HTTP"
integration_http_method = "GET"
uri = "/integration/accounts/{id}" # <--
passthrough_behavior = "WHEN_NO_MATCH"
request_parameters {
"integration.request.path.id" = "method.request.path.accountId"
}
}
不幸的是,与AWS Lambda集成使用该uri字段作为lambda的ARN。这是我在集成中引用lambda的方式:
resource "aws_api_gateway_integration" "books_lambda" {
rest_api_id = "${var.gateway.id}"
resource_id = "${var.resource_id}"
http_method = "${aws_api_gateway_method.books.http_method}"
type = "AWS_PROXY"
integration_http_method = "POST"
uri = "${var.books_invoke_arn}" # <--
credentials = "${aws_iam_role.books_gateway.arn}"
request_parameters {
"integration.request.path.id" = "method.request.path.bookId"
}
}
由于arn位于uri字段的位置,我不知道在哪里定义路径参数的放置位置。
我尝试将路径变量附加到uri字段(${var.books_invoke_arn}/{bookId}
),但是它会产生错误。当uri字段被lambda arn占用时,我应该在哪里指定路径变量?
第二个问题是,是否可以使该变量可选,还是必须拥有第二组terraform(一组带有变量,一组没有)?
谢谢!