-
Notifications
You must be signed in to change notification settings - Fork 7
/
lambda-iam.tf
57 lines (53 loc) · 1.56 KB
/
lambda-iam.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
/**
* Copyright (C) 2019-2021 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
resource "aws_iam_role" "beekeeper_slack_notifier_lambda" {
count = var.slack_lambda_enabled == 1 ? 1 : 0
name = "${local.instance_alias}-slack-notifier-lambda-${var.aws_region}"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_policy" "beekeeper_lambda_vpc_access" {
count = var.slack_lambda_enabled == 1 ? 1 : 0
name = "${local.instance_alias}-lambda-vpc-access-${var.aws_region}"
description = "VPC and CloudWatch access for Beekeeper Slack Notifier Lambda function"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "beekeeper_slack_notifier_lambda" {
count = var.slack_lambda_enabled == 1 ? 1 : 0
role = aws_iam_role.beekeeper_slack_notifier_lambda[count.index].id
policy_arn = aws_iam_policy.beekeeper_lambda_vpc_access[count.index].arn
}