-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.tf
74 lines (53 loc) · 1.77 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
# resource
resource "aws_api_gateway_resource" "resource" {
rest_api_id = var.api
parent_id = var.root_resource
path_part = var.resource
}
# resource methods
resource "aws_api_gateway_method" "method" {
for_each = toset(var.methods[*].method)
rest_api_id = var.api
resource_id = aws_api_gateway_resource.resource.id
authorization = "NONE"
api_key_required = var.api_key_required
http_method = each.key
}
resource "aws_api_gateway_method_response" "method_response" {
for_each = toset(var.methods[*].method)
depends_on = [aws_api_gateway_method.method]
rest_api_id = var.api
resource_id = aws_api_gateway_resource.resource.id
http_method = each.key
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Origin" = true
}
}
resource "aws_api_gateway_integration_response" "integration_response" {
for_each = toset(var.methods[*].method)
depends_on = [aws_api_gateway_method_response.method_response]
rest_api_id = var.api
resource_id = aws_api_gateway_resource.resource.id
http_method = each.key
status_code = "200"
}
# resource lambdas
resource "aws_api_gateway_integration" "resource_lambda_integration" {
for_each = {for m in var.methods: m.method => m}
depends_on = [aws_api_gateway_method.method]
rest_api_id = var.api
resource_id = aws_api_gateway_resource.resource.id
http_method = each.key
integration_http_method = "POST"
type = each.value.type != null ? each.value.type : "AWS_PROXY"
uri = each.value.invoke_arn
}
module "resource_cors" {
source = "mewa/apigateway-cors/aws"
version = "2.0.0"
api = var.api
resource = aws_api_gateway_resource.resource.id
methods = var.methods[*].method
origin = var.origin
}