forked from particuleio/terraform-kubernetes-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-ebs-csi-driver.tf
168 lines (152 loc) · 6.74 KB
/
aws-ebs-csi-driver.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
167
168
locals {
aws-ebs-csi-driver = merge(
local.helm_defaults,
{
name = "aws-ebs-csi-driver"
namespace = "kube-system"
chart = "aws-ebs-csi-driver"
repository = "https://particuleio.github.io/charts"
create_ns = false
service_account_names = {
controller = "ebs-csi-controller-sa"
snapshot = "ebs-snapshot-controller"
}
create_iam_resources_irsa = true
create_storage_class = true
storage_class_name = "ebs-sc"
is_default_class = false
enabled = false
chart_version = "0.9.4"
version = "v0.9.0"
iam_policy_override = null
default_network_policy = true
},
var.aws-ebs-csi-driver
)
values_aws-ebs-csi-driver = <<VALUES
image:
tag: "${local.aws-ebs-csi-driver["version"]}"
enableVolumeScheduling: true
enableVolumeResizing: true
enableVolumeSnapshot: true
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
extraCreateMetadata: true
k8sTagClusterId: ${var.cluster-name}
serviceAccount:
controller:
name: ${local.aws-ebs-csi-driver["service_account_names"]["controller"]}
annotations:
eks.amazonaws.com/role-arn: "${local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_iam_resources_irsa"] ? module.iam_assumable_role_aws-ebs-csi-driver.this_iam_role_arn : ""}"
snapshot:
create: true
name: ${local.aws-ebs-csi-driver["service_account_names"]["snapshot"]}
annotations:
eks.amazonaws.com/role-arn: "${local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_iam_resources_irsa"] ? module.iam_assumable_role_aws-ebs-csi-driver.this_iam_role_arn : ""}"
VALUES
}
module "iam_assumable_role_aws-ebs-csi-driver" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
version = "~> 3.0"
create_role = local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_iam_resources_irsa"]
role_name = "tf-${var.cluster-name}-${local.aws-ebs-csi-driver["name"]}-irsa"
provider_url = replace(var.eks["cluster_oidc_issuer_url"], "https://", "")
role_policy_arns = local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_iam_resources_irsa"] ? [aws_iam_policy.aws-ebs-csi-driver[0].arn] : []
number_of_role_policy_arns = 1
oidc_fully_qualified_subjects = [
"system:serviceaccount:${local.aws-ebs-csi-driver["namespace"]}:${local.aws-ebs-csi-driver["service_account_names"]["controller"]}",
"system:serviceaccount:${local.aws-ebs-csi-driver["namespace"]}:${local.aws-ebs-csi-driver["service_account_names"]["snapshot"]}"
]
tags = local.tags
}
resource "aws_iam_policy" "aws-ebs-csi-driver" {
count = local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_iam_resources_irsa"] ? 1 : 0
name = "tf-${var.cluster-name}-${local.aws-ebs-csi-driver["name"]}"
policy = local.aws-ebs-csi-driver["iam_policy_override"] == null ? file("${path.module}/iam/aws-ebs-csi-driver.json") : local.aws-ebs-csi-driver["iam_policy_override"]
}
resource "kubernetes_namespace" "aws-ebs-csi-driver" {
count = local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_ns"] ? 1 : 0
metadata {
labels = {
name = local.aws-ebs-csi-driver["namespace"]
}
name = local.aws-ebs-csi-driver["namespace"]
}
}
resource "helm_release" "aws-ebs-csi-driver" {
count = local.aws-ebs-csi-driver["enabled"] ? 1 : 0
repository = local.aws-ebs-csi-driver["repository"]
name = local.aws-ebs-csi-driver["name"]
chart = local.aws-ebs-csi-driver["chart"]
version = local.aws-ebs-csi-driver["chart_version"]
timeout = local.aws-ebs-csi-driver["timeout"]
force_update = local.aws-ebs-csi-driver["force_update"]
recreate_pods = local.aws-ebs-csi-driver["recreate_pods"]
wait = local.aws-ebs-csi-driver["wait"]
atomic = local.aws-ebs-csi-driver["atomic"]
cleanup_on_fail = local.aws-ebs-csi-driver["cleanup_on_fail"]
dependency_update = local.aws-ebs-csi-driver["dependency_update"]
disable_crd_hooks = local.aws-ebs-csi-driver["disable_crd_hooks"]
disable_webhooks = local.aws-ebs-csi-driver["disable_webhooks"]
render_subchart_notes = local.aws-ebs-csi-driver["render_subchart_notes"]
replace = local.aws-ebs-csi-driver["replace"]
reset_values = local.aws-ebs-csi-driver["reset_values"]
reuse_values = local.aws-ebs-csi-driver["reuse_values"]
skip_crds = local.aws-ebs-csi-driver["skip_crds"]
verify = local.aws-ebs-csi-driver["verify"]
values = [
local.values_aws-ebs-csi-driver,
local.aws-ebs-csi-driver["extra_values"]
]
namespace = local.aws-ebs-csi-driver["create_ns"] ? kubernetes_namespace.aws-ebs-csi-driver.*.metadata.0.name[count.index] : local.aws-ebs-csi-driver["namespace"]
}
resource "kubernetes_storage_class" "aws-ebs-csi-driver" {
count = local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["create_storage_class"] ? 1 : 0
metadata {
name = local.aws-ebs-csi-driver["storage_class_name"]
annotations = {
"storageclass.kubernetes.io/is-default-class" = tostring(local.aws-ebs-csi-driver["is_default_class"])
}
}
storage_provisioner = "ebs.csi.aws.com"
volume_binding_mode = "WaitForFirstConsumer"
allow_volume_expansion = true
}
resource "kubernetes_network_policy" "aws-ebs-csi-driver_default_deny" {
count = local.aws-ebs-csi-driver["create_ns"] && local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.aws-ebs-csi-driver.*.metadata.0.name[count.index]}-default-deny"
namespace = kubernetes_namespace.aws-ebs-csi-driver.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "aws-ebs-csi-driver_allow_namespace" {
count = local.aws-ebs-csi-driver["create_ns"] && local.aws-ebs-csi-driver["enabled"] && local.aws-ebs-csi-driver["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.aws-ebs-csi-driver.*.metadata.0.name[count.index]}-allow-namespace"
namespace = kubernetes_namespace.aws-ebs-csi-driver.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
from {
namespace_selector {
match_labels = {
name = kubernetes_namespace.aws-ebs-csi-driver.*.metadata.0.name[count.index]
}
}
}
}
policy_types = ["Ingress"]
}
}