-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrations.tf
87 lines (68 loc) · 2.95 KB
/
integrations.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
##################################
# ------------ CORS ------------ #
##################################
resource "aws_api_gateway_method" "this_cors" {
for_each = local.api_mock_resources
rest_api_id = local.rest_api.id
resource_id = aws_api_gateway_resource.this[each.value].id
http_method = "OPTIONS"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "this_cors" {
for_each = local.api_mock_resources
rest_api_id = local.rest_api.id
resource_id = aws_api_gateway_resource.this[each.value].id
http_method = aws_api_gateway_method.this_cors[each.value].http_method
type = "MOCK"
request_templates = {
"application/json" = jsonencode({ statusCode = 200 })
}
}
####################################
# ------------ Lambda ------------ #
####################################
resource "aws_api_gateway_method" "this_lambda" {
for_each = local.lambdas
rest_api_id = local.rest_api.id
resource_id = aws_api_gateway_resource.this[each.value.path].id
http_method = each.value.method
authorization = var.api_gtw.cognito_authorizer != null && each.value.with_autorizer ? "COGNITO_USER_POOLS" : "NONE"
authorizer_id = var.api_gtw.cognito_authorizer != null && each.value.with_autorizer ? aws_api_gateway_authorizer.this[local.gateway_name].id : null
}
resource "aws_api_gateway_integration" "this_lambda" {
for_each = local.lambdas
rest_api_id = local.rest_api.id
resource_id = aws_api_gateway_resource.this[each.value.path].id
http_method = aws_api_gateway_method.this_lambda[each.key].http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = each.value.arn
}
#################################
# ------------ SNS ------------ #
#################################
resource "aws_api_gateway_method" "this_pub_sub" {
for_each = local.sns_list
rest_api_id = local.rest_api.id
resource_id = aws_api_gateway_resource.this[each.value.path].id
http_method = each.value.method
authorization = var.api_gtw.cognito_authorizer != null && each.value.with_autorizer ? "COGNITO_USER_POOLS" : "NONE"
authorizer_id = var.api_gtw.cognito_authorizer != null && each.value.with_autorizer ? aws_api_gateway_authorizer.this[local.gateway_name].id : null
}
resource "aws_api_gateway_integration" "this_pub_sub" {
for_each = local.sns_list
rest_api_id = local.rest_api.id
resource_id = aws_api_gateway_resource.this[each.value.path].id
http_method = aws_api_gateway_method.this_pub_sub[each.key].http_method
integration_http_method = "POST"
type = "AWS"
uri = "arn:aws:apigateway:us-east-1:sns:action/Publish"
credentials = aws_iam_role.this_sns_integration_role[local.gateway_name].arn
passthrough_behavior = "WHEN_NO_TEMPLATES"
request_parameters = {
"integration.request.header.Content-Type" = "'application/x-www-form-urlencoded'"
}
request_templates = {
"application/json" = each.value.request_mapping
}
}