-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiam_linuxkit_role.tf
87 lines (73 loc) · 1.86 KB
/
iam_linuxkit_role.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
data "aws_caller_identity" "self" {}
data "aws_iam_policy_document" "linuxkit_assume" {
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "AWS"
identifiers = [data.aws_caller_identity.self.account_id]
}
}
dynamic "statement" {
for_each = toset(var.trusted_aws_principals)
content {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "AWS"
identifiers = [statement.value]
}
}
}
}
resource "aws_iam_role" "linuxkit" {
name = "linuxkit"
assume_role_policy = data.aws_iam_policy_document.linuxkit_assume.json
}
data "aws_iam_policy_document" "linuxkit_role_policy" {
statement {
actions = [
"s3:PutObject",
"s3:GetObject",
]
effect = "Allow"
resources = ["${aws_s3_bucket.staging_bucket.arn}/*"]
}
statement {
actions = [
"ec2:ImportSnapshot",
"ec2:DescribeImportSnapshotTasks",
"ec2:RegisterImage",
]
effect = "Allow"
resources = ["*"]
}
}
resource "aws_iam_policy" "linuxkit" {
name = "LinuxkitBuild"
policy = data.aws_iam_policy_document.linuxkit_role_policy.json
}
resource "aws_iam_role_policy_attachment" "linuxkit" {
role = aws_iam_role.linuxkit.name
policy_arn = aws_iam_policy.linuxkit.arn
}
resource "aws_iam_group" "linuxkit" {
count = var.create_group ? 1 : 0
name = "linuxkit"
}
data "aws_iam_policy_document" "linuxkit_policy" {
count = var.create_group ? 1 : 0
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
resources = [
aws_iam_role.linuxkit.arn,
]
}
}
resource "aws_iam_group_policy" "linuxkit_policy" {
count = var.create_group ? 1 : 0
name = "linuxkit-role-assume"
group = aws_iam_group.linuxkit[0].id
policy = data.aws_iam_policy_document.linuxkit_policy[0].json
}