forked from futurice/terraform-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_gateway_resources.tf
64 lines (54 loc) · 2.46 KB
/
api_gateway_resources.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Add root resource to the API (it it needs to be included separately from the "proxy" resource defined below), which forwards to our Lambda:
resource "aws_api_gateway_method" "proxy_root" {
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
resource_id = "${aws_api_gateway_rest_api.this.root_resource_id}"
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "proxy_root" {
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
resource_id = "${aws_api_gateway_method.proxy_root.resource_id}"
http_method = "${aws_api_gateway_method.proxy_root.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${local.function_invoke_arn}"
}
# Add a "proxy" resource, that matches all paths (except the root, defined above) and forwards them to our Lambda:
resource "aws_api_gateway_resource" "proxy_other" {
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
parent_id = "${aws_api_gateway_rest_api.this.root_resource_id}"
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "proxy_other" {
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
resource_id = "${aws_api_gateway_resource.proxy_other.id}"
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "proxy_other" {
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
resource_id = "${aws_api_gateway_method.proxy_other.resource_id}"
http_method = "${aws_api_gateway_method.proxy_other.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${local.function_invoke_arn}"
}
resource "aws_api_gateway_method_response" "proxy_other" {
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
resource_id = "${aws_api_gateway_resource.proxy_other.id}"
http_method = "${aws_api_gateway_method.proxy_other.http_method}"
status_code = "200"
response_models = {
"application/json" = "Empty"
}
}
resource "aws_api_gateway_integration_response" "proxy_other" {
depends_on = ["aws_api_gateway_integration.proxy_other"]
rest_api_id = "${aws_api_gateway_rest_api.this.id}"
resource_id = "${aws_api_gateway_resource.proxy_other.id}"
http_method = "${aws_api_gateway_method.proxy_other.http_method}"
status_code = "${aws_api_gateway_method_response.proxy_other.status_code}"
response_templates = {
"application/json" = ""
}
}