-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail_api.tf
65 lines (58 loc) · 3.18 KB
/
email_api.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
resource "aws_api_gateway_rest_api" "website_api" {
name = "website_api"
description = "API for static website functions"
}
resource "aws_api_gateway_resource" "website_api_email_resource" {
path_part = "messages"
parent_id = "${aws_api_gateway_rest_api.website_api.root_resource_id}"
rest_api_id = "${aws_api_gateway_rest_api.website_api.id}"
}
resource "aws_api_gateway_method" "website_api_email_method" {
rest_api_id = "${aws_api_gateway_rest_api.website_api.id}"
resource_id = "${aws_api_gateway_resource.website_api_email_resource.id}"
http_method = "POST"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "website_api_email_method_integration" {
rest_api_id = "${aws_api_gateway_rest_api.website_api.id}"
resource_id = "${aws_api_gateway_resource.website_api_email_resource.id}"
http_method = "${aws_api_gateway_method.website_api_email_method.http_method}"
type = "AWS_PROXY"
integration_http_method = "POST"
uri = "arn:aws:apigateway:${var.aws_region}:lambda:path/2015-03-31/functions/${aws_lambda_function.lambda_email_function.arn}/invocations"
}
resource "aws_api_gateway_method_response" "website_api_email_response_method" {
rest_api_id = "${aws_api_gateway_rest_api.website_api.id}"
resource_id = "${aws_api_gateway_resource.website_api_email_resource.id}"
http_method = "${aws_api_gateway_integration.website_api_email_method_integration.http_method}"
status_code = "200"
response_models = { "application/json" = "Empty" }
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = true,
"method.response.header.Access-Control-Allow-Methods" = true,
"method.response.header.Access-Control-Allow-Origin" = true
}
}
resource "aws_api_gateway_integration_response" "website_api_email_method_integration" {
rest_api_id = "${aws_api_gateway_rest_api.website_api.id}"
resource_id = "${aws_api_gateway_resource.website_api_email_resource.id}"
http_method = "${aws_api_gateway_method_response.website_api_email_response_method.http_method}"
status_code = "200"
response_parameters = {
"method.response.header.Access-Control-Allow-Headers" = "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
"method.response.header.Access-Control-Allow-Methods" = "'POST,OPTIONS,GET,PUT,PATCH,DELETE'",
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}
resource "aws_api_gateway_deployment" "website_email_api_prod" {
depends_on = [
"aws_api_gateway_method.website_api_email_method",
"aws_api_gateway_integration.website_api_email_method_integration"
]
rest_api_id = "${aws_api_gateway_rest_api.website_api.id}"
stage_name = "api"
provisioner "local-exec" {
command = "export EMAIL_CONFIG_FILE_VAR=${var.config_file}; if [! -z "$EMAIL_CONFIG_FILE_VAR" ]; then python ${path.module}/utils/update_config.py --api_url https://${aws_api_gateway_deployment.website_email_api_prod.rest_api_id}.execute-api.${var.aws_region}.amazonaws.com/${aws_api_gateway_deployment.website_email_api_prod.stage_name} ${var.config_file}; fi"
on_failure = "continue"
}
}