-
Notifications
You must be signed in to change notification settings - Fork 28
/
iam.tf
166 lines (138 loc) · 3.68 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
data "aws_iam_policy_document" "ebs_controller_policy" {
statement {
effect = "Allow"
resources = ["*"]
actions = [
"ec2:CreateSnapshot",
"ec2:AttachVolume",
"ec2:DetachVolume",
"ec2:ModifyVolume",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeInstances",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:DescribeVolumes",
"ec2:DescribeVolumesModifications",
]
}
statement {
effect = "Allow"
resources = [
"arn:${var.arn_format}:ec2:*:*:volume/*",
"arn:${var.arn_format}:ec2:*:*:snapshot/*",
]
actions = ["ec2:CreateTags"]
condition {
test = "StringEquals"
variable = "ec2:CreateAction"
values = [
"CreateVolume",
"CreateSnapshot",
]
}
}
statement {
effect = "Allow"
resources = [
"arn:${var.arn_format}:ec2:*:*:volume/*",
"arn:${var.arn_format}:ec2:*:*:snapshot/*",
]
actions = ["ec2:DeleteTags"]
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:CreateVolume"]
condition {
test = "StringLike"
variable = "aws:RequestTag/ebs.csi.aws.com/cluster"
values = ["true"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:CreateVolume"]
condition {
test = "StringLike"
variable = "aws:RequestTag/CSIVolumeName"
values = ["*"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:CreateVolume"]
condition {
test = "StringLike"
variable = "aws:RequestTag/kubernetes.io/cluster/*"
values = ["owned"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:DeleteVolume"]
condition {
test = "StringLike"
variable = "ec2:ResourceTag/ebs.csi.aws.com/cluster"
values = ["true"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:DeleteVolume"]
condition {
test = "StringLike"
variable = "ec2:ResourceTag/CSIVolumeName"
values = ["*"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:DeleteVolume"]
condition {
test = "StringLike"
variable = "ec2:ResourceTag/kubernetes.io/cluster/*"
values = ["owned"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:DeleteSnapshot"]
condition {
test = "StringLike"
variable = "ec2:ResourceTag/CSIVolumeSnapshotName"
values = ["*"]
}
}
statement {
effect = "Allow"
resources = ["*"]
actions = ["ec2:DeleteSnapshot"]
condition {
test = "StringLike"
variable = "ec2:ResourceTag/ebs.csi.aws.com/cluster"
values = ["true"]
}
}
}
resource "aws_iam_policy" "ebs_controller_policy" {
name_prefix = var.ebs_csi_controller_role_policy_name_prefix
policy = data.aws_iam_policy_document.ebs_controller_policy.json
tags = var.tags
}
module "ebs_controller_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "4.24.1"
create_role = true
role_description = "EBS CSI Driver Role"
role_name_prefix = var.ebs_csi_controller_role_name
provider_url = var.oidc_url
role_policy_arns = concat([aws_iam_policy.ebs_controller_policy.arn], var.additional_iam_policies_arns)
oidc_fully_qualified_subjects = ["system:serviceaccount:${var.namespace}:${local.controller_name}"]
tags = var.tags
}