-
Notifications
You must be signed in to change notification settings - Fork 2
/
lambda.tf
56 lines (46 loc) · 1.28 KB
/
lambda.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
locals {
lambda_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
data "archive_file" "notifications_lambda" {
type = "zip"
output_path = "${path.module}/notifications.zip"
source_dir = "${path.module}/files/notifications/"
}
resource "random_id" "generator" {
byte_length = 8
}
resource "aws_iam_role" "iam_for_lambda" {
name = "notifications_lambda_${random_id.generator.id}"
assume_role_policy = local.lambda_role_policy
}
resource "aws_lambda_function" "notifications_lambda" {
filename = "${path.module}/notifications.zip"
function_name = "notifications_${random_id.generator.id}"
role = aws_iam_role.iam_for_lambda.arn
handler = "notifications.notifications"
runtime = "python3.6"
environment {
variables = {
SLACK_WEBHOOK_URL = var.slack_webhook_url
SLACK_CHANNEL = var.slack_channel
SLACK_USERNAME = var.slack_username
S3_BUCKET_NAME = var.s3_bucket_name
CW_LOG_GROUPS = jsonencode(var.cloudwatch_subscripted_log_group_names)
SNS_TOPIC_ARNS = jsonencode(var.sns_subscripted_topics_arns)
}
}
}