我正在尝试使用Terraform能够在AWS上的API网关中 Build 一个简单的API代理 . 基本上,我想包装root并将请求代理回另一个 endpoints . 它可能是最简单的设置,我似乎无法让它在Terraform中工作 .
您将在下面找到该脚本 . 此时,我能够创建REST API,定义资源,创建方法,但似乎没有任何方法可以定义它的终点 .
provider "aws" {
region = "us-east-1"
}
resource "aws_api_gateway_rest_api" "TerraTest" {
name = "TerraTest"
description = "This is my API for demonstration purposes"
}
resource "aws_api_gateway_resource" "TerraProxyResource" {
rest_api_id = "${aws_api_gateway_rest_api.TerraTest.id}"
parent_id = "${aws_api_gateway_rest_api.TerraTest.root_resource_id}"
path_part = "{proxy+}"
}
resource "aws_api_gateway_integration" "integration" {
rest_api_id = "${aws_api_gateway_rest_api.TerraTest.id}"
resource_id = "${aws_api_gateway_resource.TerraProxyResource.id}"
http_method = "${aws_api_gateway_method.mymethod.http_method}"
type = "HTTP_PROXY"
uri = "http://api.endpoint.com/{proxy+}"
}
这里我将类型设置为proxy,但我认为URI不是设置 endpoints 的正确属性 .
resource "aws_api_gateway_method" "mymethod" {
rest_api_id = "${aws_api_gateway_rest_api.TerraTest.id}"
resource_id = "${aws_api_gateway_resource.TerraProxyResource.id}"
http_method = "ANY"
authorization = "NONE"
}
我希望这里的某个地方能够创建到其他 endpoints 的映射,但似乎没有任何属性 . (https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_api_gateway_method.go)
resource "aws_api_gateway_api_key" "TerraTestKey" {
name = "Terra_Test_Key"
stage_key {
rest_api_id = "${aws_api_gateway_rest_api.TerraTest.id}"
stage_name = "${aws_api_gateway_deployment.TerraTestDeployment.stage_name}"
}
}
resource "aws_api_gateway_deployment" "TerraTestDeployment" {
rest_api_id = "${aws_api_gateway_rest_api.TerraTest.id}"
stage_name = "dev"
}
我扫描了源代码,但没有看到任何可以设置的属性 .
任何人都可以分享任何建议/狙击手吗?
蒂姆
PS . 如果你想尝试自己运行脚本,我把它放在这里:http://textuploader.com/d14sx
1 回答
这是显示工作解决方案的相关模块 . 它不是孤立的,因为它依赖于其他地方定义的一些变量,但它应该足以帮助任何努力获得AWS代理设置并且还显示Lambda授权器集成作为奖励 .