forked from telia-oss/terraform-aws-lambda-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
44 lines (39 loc) · 1.28 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
resource "random_string" "lambda_postfix_generator" {
length = 16
upper = true
lower = true
number = true
special = false
}
resource "aws_sns_topic" "alarm_topic" {
name = "${var.topic_name}${var.has_random_postfix ? "-${random_string.lambda_postfix_generator.result}" : ""}"
}
resource "aws_lambda_function" "notify_slack" {
s3_bucket = var.lambda_s3_bucket
s3_key = var.s3_key
function_name = "${var.name_prefix}-slack-notify${var.has_random_postfix ? "-${random_string.lambda_postfix_generator.result}" : ""}"
handler = var.handler
runtime = "go1.x"
timeout = var.timeout
memory_size = var.memory_size
role = aws_iam_role.lambda_role.arn
environment {
variables = {
SLACK_HOOK = var.slack_hook
USERNAME = var.username
ICON = var.icon
}
}
}
resource "aws_lambda_permission" "allow_sns" {
statement_id = "AllowExecutionFromSNS"
action = "lambda:invokeFunction"
function_name = aws_lambda_function.notify_slack.arn
principal = "sns.amazonaws.com"
source_arn = aws_sns_topic.alarm_topic.arn
}
resource "aws_sns_topic_subscription" "lambda_sns" {
topic_arn = aws_sns_topic.alarm_topic.arn
protocol = "lambda"
endpoint = aws_lambda_function.notify_slack.arn
}