-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_gateway_main.tf
139 lines (111 loc) · 4.59 KB
/
api_gateway_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
resource "aws_api_gateway_rest_api" "route53_api" {
name = "Route53FlashpointAPI"
description = "API for Route53Flashpoint DNS Management"
tags = var.common_tags
endpoint_configuration {
types = ["REGIONAL"]
}
}
resource "aws_api_gateway_deployment" "route53_api_deployment" {
depends_on = [
aws_api_gateway_integration.create_record_lambda_integration,
aws_api_gateway_integration.delete_record_lambda_integration,
aws_api_gateway_integration.reports_lambda_integration,
]
rest_api_id = aws_api_gateway_rest_api.route53_api.id
stage_name = "v1"
#Forces a redeployment of the API Gateway when the Lambda functions are updated
triggers = {
redeployment = sha1(join("", tolist([
aws_api_gateway_integration.create_record_lambda_integration.id,
aws_api_gateway_integration.delete_record_lambda_integration.id,
aws_api_gateway_integration.reports_lambda_integration.id,
var.force_deploy
])))
}
}
resource "aws_api_gateway_resource" "dns_record_resource" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
parent_id = aws_api_gateway_rest_api.route53_api.root_resource_id
path_part = "route53dnsrecord"
}
resource "aws_api_gateway_resource" "reports_resource" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
parent_id = aws_api_gateway_rest_api.route53_api.root_resource_id
path_part = "reports"
}
##Create Route53 Records Endpoint
resource "aws_api_gateway_method" "create_dns_record_post" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.dns_record_resource.id
http_method = "POST"
authorization = "AWS_IAM"
}
resource "aws_api_gateway_integration" "create_record_lambda_integration" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.dns_record_resource.id
http_method = aws_api_gateway_method.create_dns_record_post.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.create_record_lambda.invoke_arn
credentials = aws_iam_role.api_gateway_lambda_role.arn
}
resource "aws_api_gateway_method_response" "create_response_200" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.dns_record_resource.id
http_method = aws_api_gateway_method.create_dns_record_post.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
}
##Delete Route53 Records Endpoint
resource "aws_api_gateway_method" "delete_dns_record_delete" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.dns_record_resource.id
http_method = "DELETE"
authorization = "AWS_IAM"
}
resource "aws_api_gateway_integration" "delete_record_lambda_integration" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.dns_record_resource.id
http_method = aws_api_gateway_method.delete_dns_record_delete.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.delete_expired_records_lambda.invoke_arn
credentials = aws_iam_role.api_gateway_lambda_role.arn
}
resource "aws_api_gateway_method_response" "delete_response_200" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.dns_record_resource.id
http_method = aws_api_gateway_method.delete_dns_record_delete.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
}
##Reports Endpoint
resource "aws_api_gateway_method" "reports_post" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.reports_resource.id
http_method = "POST"
authorization = "AWS_IAM"
}
resource "aws_api_gateway_integration" "reports_lambda_integration" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.reports_resource.id
http_method = aws_api_gateway_method.reports_post.http_method
integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.records_report_lambda.invoke_arn
credentials = aws_iam_role.api_gateway_lambda_role.arn
}
resource "aws_api_gateway_method_response" "reports_response_200" {
rest_api_id = aws_api_gateway_rest_api.route53_api.id
resource_id = aws_api_gateway_resource.reports_resource.id
http_method = aws_api_gateway_method.reports_post.http_method
status_code = "200"
response_models = {
"application/json" = "Empty"
}
}