-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
105 lines (95 loc) · 2.32 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
resource "aws_iam_role" "lambda_exec" {
name = "${var.function_name}_basic_execution"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_policy" "log_access" {
name = "${var.function_name}_log_access"
path = "/"
description = "Allows ${var.function_name} access to the required logging"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_policy" "ecr_access" {
name = "${var.function_name}_ecr_access"
path = "/"
description = "Allows ${var.function_name} access to the required ecs and ecr items"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ecr:DescribeImageScanFindings"
],
"Resource": [
"*"
],
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_policy" "kms_access" {
name = "${var.function_name}_kms_decrypt_access"
path = "/"
description = "Allows ${var.function_name} access to decrypt the KMS key"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "kms:Decrypt",
"Resource": [
"${aws_kms_key.slack_lambda.arn}"
]
}
]
}
EOF
}
resource "aws_iam_policy_attachment" "kms_access" {
name = "kms access"
roles = ["${aws_iam_role.lambda_exec.name}"]
policy_arn = "${aws_iam_policy.kms_access.arn}"
}
resource "aws_iam_policy_attachment" "log_access" {
name = "log access"
roles = ["${aws_iam_role.lambda_exec.name}"]
policy_arn = "${aws_iam_policy.log_access.arn}"
}
resource "aws_iam_policy_attachment" "ecr_access" {
name = "ecr access"
roles = ["${aws_iam_role.lambda_exec.name}"]
policy_arn = "${aws_iam_policy.ecr_access.arn}"
}