-
Notifications
You must be signed in to change notification settings - Fork 8
/
iam.tf
49 lines (40 loc) · 1.09 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
data "aws_iam_policy_document" "trust_policy" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
"ssm.amazonaws.com",
]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "this" {
name = local.name
assume_role_policy = data.aws_iam_policy_document.trust_policy.json
}
resource "aws_iam_role_policy_attachment" "this" {
for_each = toset(["arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore", "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"])
role = aws_iam_role.this.name
policy_arn = each.key
}
data "aws_iam_policy_document" "kms_key_policy_iam_profile" {
statement {
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [aws_kms_key.this.arn]
}
}
resource "aws_iam_role_policy" "kms" {
role = aws_iam_role.this.name
name = "inline-policy-kms-access"
policy = data.aws_iam_policy_document.kms_key_policy_iam_profile.json
}
resource "aws_iam_instance_profile" "this" {
name = local.name
role = aws_iam_role.this.name
}