-
Notifications
You must be signed in to change notification settings - Fork 9
/
iam.tf
62 lines (55 loc) · 1.45 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
data "aws_iam_policy_document" "this" {
statement {
sid = "IamPassRole"
actions = ["iam:PassRole"]
resources = ["*"]
condition {
test = "StringEquals"
variable = "iam:PassedToService"
values = ["ec2.amazonaws.com"]
}
}
statement {
sid = "ListEc2AndListInstanceProfiles"
actions = [
"iam:ListInstanceProfiles",
"ec2:Describe*",
"ec2:Search*",
"ec2:Get*"
]
resources = ["*"]
condition {
test = "StringEquals"
variable = "iam:PassedToService"
values = ["ec2.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "this_assume_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "aws_iam_role" "this" {
name = format("%s-role", local.name)
path = "/"
assume_role_policy = data.aws_iam_policy_document.this_assume_role.json
}
resource "aws_iam_role_policy" "this" {
name = format("%s-policy", local.name)
role = aws_iam_role.this.id
policy = data.aws_iam_policy_document.this.json
}
resource "aws_iam_role_policy_attachment" "this" {
count = length(local.profile_policy_arns)
role = aws_iam_role.this.name
policy_arn = local.profile_policy_arns[count.index]
}
resource "aws_iam_instance_profile" "this" {
name = format("%s-profile", local.name)
role = aws_iam_role.this.name
}