-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
74 lines (61 loc) · 1.96 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
terraform {
required_version = ">= 0.12.0"
}
# API Gateway
resource "aws_api_gateway_rest_api" "api" {
name = var.apigw_name
}
resource "aws_api_gateway_resource" "resource" {
parent_id = aws_api_gateway_rest_api.api.root_resource_id
rest_api_id = aws_api_gateway_rest_api.api.id
path_part = "{proxy+}"
}
resource "aws_api_gateway_method" "method" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = var.http_method
authorization = "NONE"
}
resource "aws_api_gateway_integration" "integration" {
rest_api_id = aws_api_gateway_rest_api.api.id
resource_id = aws_api_gateway_resource.resource.id
http_method = aws_api_gateway_method.method.http_method
integration_http_method = var.integration_http_method
type = "AWS_PROXY"
uri = aws_lambda_function.lambda.invoke_arn
}
resource "aws_api_gateway_deployment" "deployment" {
rest_api_id = aws_api_gateway_rest_api.api.id
stage_name = var.stage_name
depends_on = [
"aws_api_gateway_integration.integration"
]
}
# Lambda
resource "aws_lambda_permission" "apigw_lambda" {
statement_id = "AllowExecutionFromAPIGateway"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.api.execution_arn}/*/*/*"
}
resource "aws_lambda_function" "lambda" {
s3_bucket = var.s3_bucket
s3_key = var.s3_key
function_name = var.function_name
handler = var.handler
role = var.lambda_role
timeout = var.timeout
memory_size = var.memory_size
runtime = var.runtime
environment {
variables = var.env_vars
}
dynamic "vpc_config" {
for_each = var.subnet_ids != null ? { dummy : "hoge" } : {}
content {
subnet_ids = var.subnet_ids
security_group_ids = var.security_group_ids
}
}
}