This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
generated from TechNative-B-V/terraform-aws-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
95 lines (80 loc) · 2.24 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
module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"
version = "3.3.1"
function_name = var.name
description = "Sends mails at HTML Form submissions"
handler = "html_form_action.lambda_handler"
runtime = "python3.9"
source_path = [
format("%s/lambda_src", abspath(path.module)),
{
#pip_requirements = format("%s/lambda-src/requirements.txt", abspath(path.module))
}
]
publish = true
timeout = 15
environment_variables = {
TO_MAIL = var.to_email
FROM_MAIL = var.from_email
}
attach_policy_json = true
policy_json = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": "ses:SendEmail",
"Resource": "*"
}
]
}
EOF
}
resource "aws_lambda_permission" "lambda_permission" {
statement_id = "AllowAPIInvoke"
action = "lambda:InvokeFunction"
function_name = var.name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.main.execution_arn}/*/*"
}
resource "aws_api_gateway_rest_api" "main" {
name = var.name
}
resource "aws_api_gateway_resource" "message" {
rest_api_id = aws_api_gateway_rest_api.main.id
parent_id = aws_api_gateway_rest_api.main.root_resource_id
path_part = "message"
}
resource "aws_api_gateway_method" "message" {
rest_api_id = aws_api_gateway_rest_api.main.id
resource_id = aws_api_gateway_resource.message.id
http_method = "POST"
authorization = "NONE"
api_key_required = false
}
resource "aws_api_gateway_integration" "message" {
rest_api_id = aws_api_gateway_rest_api.main.id
resource_id = aws_api_gateway_resource.message.id
http_method = "POST"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.lambda_function.lambda_function_invoke_arn
depends_on = [aws_api_gateway_method.message]
}
resource "aws_api_gateway_deployment" "main" {
stage_name = "main"
rest_api_id = aws_api_gateway_rest_api.main.id
depends_on = [
aws_api_gateway_integration.message,
]
}
module "resource_cors" {
source = "mewa/apigateway-cors/aws"
version = "2.0.0"
api = aws_api_gateway_rest_api.main.id
resource = aws_api_gateway_resource.message.id
methods = ["POST"]
origin = var.allowed_origin
}