-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20-efs.tf
109 lines (87 loc) · 2.92 KB
/
20-efs.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
resource "aws_efs_file_system" "eks" {
creation_token = "eks"
performance_mode = "generalPurpose"
throughput_mode = "bursting"
encrypted = true
# lifecycle_policy {
# transition_to_ia = "AFTER_30_DAYS"
# }
}
resource "aws_efs_mount_target" "zone_a" {
file_system_id = aws_efs_file_system.eks.id
subnet_id = aws_subnet.private_zone1.id
security_groups = [aws_eks_cluster.eks.vpc_config[0].cluster_security_group_id]
}
resource "aws_efs_mount_target" "zone_b" {
file_system_id = aws_efs_file_system.eks.id
subnet_id = aws_subnet.private_zone2.id
security_groups = [aws_eks_cluster.eks.vpc_config[0].cluster_security_group_id]
}
data "aws_iam_policy_document" "efs_csi_driver" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "${replace(aws_iam_openid_connect_provider.eks.url, "https://", "")}:sub"
values = ["system:serviceaccount:kube-system:efs-csi-controller-sa"]
}
principals {
identifiers = [aws_iam_openid_connect_provider.eks.arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "efs_csi_driver" {
name = "${aws_eks_cluster.eks.name}-efs-csi-driver"
assume_role_policy = data.aws_iam_policy_document.efs_csi_driver.json
}
resource "aws_iam_role_policy_attachment" "efs_csi_driver" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEFSCSIDriverPolicy"
role = aws_iam_role.efs_csi_driver.name
}
resource "helm_release" "efs_csi_driver" {
name = "aws-efs-csi-driver"
repository = "https://kubernetes-sigs.github.io/aws-efs-csi-driver/"
chart = "aws-efs-csi-driver"
namespace = "kube-system"
version = "3.0.5"
set {
name = "controller.serviceAccount.name"
value = "efs-csi-controller-sa"
}
set {
name = "controller.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
value = aws_iam_role.efs_csi_driver.arn
}
depends_on = [
aws_efs_mount_target.zone_a,
aws_efs_mount_target.zone_b
]
}
# Optional since we already init helm provider (just to make it self contained)
data "aws_eks_cluster" "eks_v2" {
name = aws_eks_cluster.eks.name
}
# Optional since we already init helm provider (just to make it self contained)
data "aws_eks_cluster_auth" "eks_v2" {
name = aws_eks_cluster.eks.name
}
provider "kubernetes" {
host = data.aws_eks_cluster.eks_v2.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks_v2.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.eks_v2.token
}
resource "kubernetes_storage_class_v1" "efs" {
metadata {
name = "efs"
}
storage_provisioner = "efs.csi.aws.com"
parameters = {
provisioningMode = "efs-ap"
fileSystemId = aws_efs_file_system.eks.id
directoryPerms = "700"
}
mount_options = ["iam"]
depends_on = [helm_release.efs_csi_driver]
}