forked from terraform-aws-modules/terraform-aws-notify-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
89 lines (64 loc) · 1.64 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
data "aws_iam_policy_document" "assume_role" {
count = var.create ? 1 : 0
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "lambda_basic" {
count = var.create ? 1 : 0
statement {
sid = "AllowWriteToCloudwatchLogs"
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = ["arn:aws:logs:*:*:*"]
}
statement {
sid = "AllowXRay"
effect = "Allow"
actions = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets",
"xray:GetSamplingStatisticSummaries",
]
resources = ["*"]
}
}
data "aws_iam_policy_document" "lambda" {
count = var.kms_key_arn != "" && var.create ? 1 : 0
source_policy_documents = data.aws_iam_policy_document.lambda_basic[0].json
statement {
sid = "AllowKMSDecrypt"
effect = "Allow"
actions = ["kms:Decrypt"]
resources = [var.kms_key_arn]
}
}
resource "aws_iam_role" "lambda" {
count = var.create ? 1 : 0
name_prefix = "lambda"
assume_role_policy = data.aws_iam_policy_document.assume_role[0].json
tags = merge(var.tags, var.iam_role_tags)
}
resource "aws_iam_role_policy" "lambda" {
count = var.create ? 1 : 0
name_prefix = "lambda-policy-"
role = aws_iam_role.lambda[0].id
policy = element(
concat(
data.aws_iam_policy_document.lambda.*.json,
data.aws_iam_policy_document.lambda_basic.*.json,
),
0,
)
}