This repository was archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
128 lines (103 loc) · 3.9 KB
/
main.tf
File metadata and controls
128 lines (103 loc) · 3.9 KB
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
provider "aws" {
region = "eu-west-1"
shared_credentials_file = ".aws_credentials"
profile = "default"
}
resource "aws_lambda_function" "rss_from_graphcool" {
function_name = "CCM_RSS"
# The bucket name as created earlier with "aws s3api create-bucket"
s3_bucket = "ccmrsslambdabuilds"
s3_key = "bundle.zip"
# "main" is the filename within the zip file (main.js) and "handler"
# is the name of the property under which the handler function was
# exported in that file.
handler = "bundle.handler"
runtime = "nodejs8.10"
# graphcool is sometimes slow...
timeout = 10
role = "${aws_iam_role.ccm_rss_lambda_exec.arn}"
}
resource "aws_iam_role" "ccm_rss_lambda_exec" {
name = "CCM_RSS_Lambda"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_api_gateway_rest_api" "ccm_api_gateway" {
name = "CCM_API_Gateway"
description = "CCM API Gateway"
}
resource "aws_api_gateway_resource" "CCM_RSS" {
rest_api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
parent_id = "${aws_api_gateway_rest_api.ccm_api_gateway.root_resource_id}"
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "proxy" {
rest_api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
resource_id = "${aws_api_gateway_resource.CCM_RSS.id}"
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "gateway_to_lambda" {
rest_api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
resource_id = "${aws_api_gateway_method.proxy.resource_id}"
http_method = "${aws_api_gateway_method.proxy.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.rss_from_graphcool.invoke_arn}"
}
resource "aws_api_gateway_method" "proxy_root" {
rest_api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
resource_id = "${aws_api_gateway_rest_api.ccm_api_gateway.root_resource_id}"
http_method = "ANY"
authorization = "NONE"
}
resource "aws_api_gateway_integration" "gateway_to_lambda_root" {
rest_api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
resource_id = "${aws_api_gateway_method.proxy_root.resource_id}"
http_method = "${aws_api_gateway_method.proxy_root.http_method}"
integration_http_method = "POST"
type = "AWS_PROXY"
uri = "${aws_lambda_function.rss_from_graphcool.invoke_arn}"
}
resource "aws_api_gateway_deployment" "production" {
depends_on = [
"aws_api_gateway_integration.gateway_to_lambda",
"aws_api_gateway_integration.gateway_to_lambda_root",
]
rest_api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
stage_name = "production"
}
resource "aws_lambda_permission" "lambda_permission" {
statement_id = "AllowInvocationFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = "${aws_lambda_function.rss_from_graphcool.arn}"
principal = "apigateway.amazonaws.com"
# The /*/*/* part allows invocation from any stage, method and resource path
# within API Gateway REST API.
source_arn = "${aws_api_gateway_rest_api.ccm_api_gateway.execution_arn}/*/*/*"
}
resource "aws_api_gateway_domain_name" "rss_christchurchmayfair_org" {
domain_name = "rss.christchurchmayfair.org"
certificate_arn = "arn:aws:acm:us-east-1:284914177938:certificate/dd6e91ef-1a52-4c40-9910-8cad6ffd17ef"
}
resource "aws_api_gateway_base_path_mapping" "production_mapping" {
api_id = "${aws_api_gateway_rest_api.ccm_api_gateway.id}"
stage_name = "${aws_api_gateway_deployment.production.stage_name}"
domain_name = "${aws_api_gateway_domain_name.rss_christchurchmayfair_org.domain_name}"
}
output "base_url" {
value = "${aws_api_gateway_deployment.production.invoke_url}"
}