-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.tf
105 lines (83 loc) · 3.03 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
data "aws_region" "current" {}
resource "aws_api_gateway_method" "method" {
rest_api_id = "${var.api_id}"
resource_id = "${var.api_resource_id}"
http_method = "${var.method}"
authorization = "${var.authorization}"
authorizer_id = "${var.authorizer_id}"
authorization_scopes = "${var.authorization_scopes}"
api_key_required = "${var.api_key_required}"
request_validator_id = "${var.request_validator_id}"
request_parameters = "${var.request_parameters}"
request_models {
"application/json" = "${var.request_model}"
}
}
resource "aws_api_gateway_integration" "integration" {
rest_api_id = "${var.api_id}"
resource_id = "${var.api_resource_id}"
http_method = "${aws_api_gateway_method.method.http_method}"
type = "AWS"
integration_http_method = "POST"
passthrough_behavior = "WHEN_NO_TEMPLATES"
uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/${var.lambda}/invocations"
request_templates {
"application/json" = "${var.request_template}"
}
depends_on = ["aws_api_gateway_method.method"]
}
resource "aws_api_gateway_method_response" "200" {
rest_api_id = "${var.api_id}"
resource_id = "${var.api_resource_id}"
http_method = "${aws_api_gateway_method.method.http_method}"
status_code = "200"
response_parameters {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models {
"application/json" = "${var.response_model}"
}
depends_on = ["aws_api_gateway_method.method"]
}
resource "aws_api_gateway_method_response" "400" {
rest_api_id = "${var.api_id}"
resource_id = "${var.api_resource_id}"
http_method = "${aws_api_gateway_method.method.http_method}"
status_code = "400"
response_parameters {
"method.response.header.Access-Control-Allow-Origin" = true
}
response_models {
"application/json" = "Error"
}
depends_on = ["aws_api_gateway_method.method"]
}
resource "aws_api_gateway_integration_response" "200" {
rest_api_id = "${var.api_id}"
resource_id = "${var.api_resource_id}"
http_method = "${aws_api_gateway_method.method.http_method}"
status_code = "${aws_api_gateway_method_response.200.status_code}"
response_parameters {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
depends_on = ["aws_api_gateway_method.method", "aws_api_gateway_method_response.200"]
}
resource "aws_api_gateway_integration_response" "400" {
rest_api_id = "${var.api_id}"
resource_id = "${var.api_resource_id}"
http_method = "${aws_api_gateway_method.method.http_method}"
status_code = "${aws_api_gateway_method_response.400.status_code}"
selection_pattern = ".+"
response_parameters {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
response_templates = {
"application/json" = <<EOF
#set($message = $util.escapeJavaScript($input.path('$.errorMessage')))
{
"message": "$message"
}
EOF
}
depends_on = ["aws_api_gateway_method.method", "aws_api_gateway_method_response.400"]
}