-
Notifications
You must be signed in to change notification settings - Fork 1
/
iam.tf
41 lines (34 loc) · 880 Bytes
/
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
/*
Define default IAM role & policy
*/
resource "aws_iam_role" "this" {
count = var.role == null ? 1 : 0
name = "lambda-${var.function_name}"
assume_role_policy = data.aws_iam_policy_document.lambda-assume-role[0].json
tags = var.tags
}
resource "aws_iam_role_policy" "this" {
count = var.role == null ? 1 : 0
role = aws_iam_role.this[0].name
name = "lambda-policy-${var.function_name}"
policy = data.aws_iam_policy_document.ec2[0].json
}
data "aws_iam_policy_document" "lambda-assume-role" {
count = var.role == null ? 1 : 0
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "ec2" {
count = var.role == null ? 1 : 0
statement {
actions = [
"ec2:DescribeSecurityGroups"
]
resources = ["*"]
}
}