-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
70 lines (61 loc) · 1.86 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
// IAM Role for Lambda Function
resource "aws_iam_role" "default" {
name = var.service_name
description = "IAM Rolw for ${var.service_name}"
assume_role_policy = file("${var.service_name}_role.json")
}
resource "aws_iam_policy" "default" {
name = var.service_name
description = "IAM Policy for ${var.service_name}"
policy = file("${var.service_name}_policy.json")
}
resource "aws_iam_role_policy_attachment" "default" {
role = aws_iam_role.default.name
policy_arn = aws_iam_policy.default.arn
}
// Lambda Function Resources
resource "aws_cloudwatch_log_group" "default" {
name = "/aws/lambda/${var.service_name}"
retention_in_days = 7
}
data archive_file "default" {
type = "zip"
source_dir = "src"
output_path = var.output_path
}
resource "aws_lambda_function" "default" {
filename = var.output_path
function_name = var.service_name
role = aws_iam_role.default.arn
handler = "lambda_function.lambda_handler"
source_code_hash = data.archive_file.default.output_base64sha256
runtime = "python3.6"
environment {
variables = {
SLACK_API_KEY = var.SLACK_API_KEY
}
}
}
// SNS Resources
/*
resource "aws_sns_topic" "default" {
name = var.service_name
delivery_policy = file("sns_delivery_policy.json")
}
resource "aws_sns_topic_subscription" "default" {
topic_arn = aws_sns_topic.default.arn
protocol = "lambda"
endpoint = aws_lambda_function.default.arn
}
*/
// SQS
resource "aws_sqs_queue" "default" {
name = "${var.service_name}.fifo"
fifo_queue = true
content_based_deduplication = true
}
// SQSとLambdaのトリガ
resource "aws_lambda_event_source_mapping" "default" {
event_source_arn = aws_sqs_queue.default.arn
function_name = aws_lambda_function.default.arn
}