-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathefs.tf
85 lines (78 loc) · 2.13 KB
/
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
resource "aws_efs_file_system" "cloud_native_workstation" {
creation_token = var.eks_cluster_name
encrypted = true
tags = var.aws_tags
}
resource "aws_efs_mount_target" "mount0" {
file_system_id = aws_efs_file_system.cloud_native_workstation.id
subnet_id = module.vpc.private_subnets[0]
security_groups = [
module.eks.cluster_primary_security_group_id,
module.eks.worker_security_group_id,
]
}
resource "aws_efs_mount_target" "mount1" {
file_system_id = aws_efs_file_system.cloud_native_workstation.id
subnet_id = module.vpc.private_subnets[1]
security_groups = [
module.eks.cluster_primary_security_group_id,
module.eks.worker_security_group_id,
]
}
resource "aws_iam_role" "eks_efs" {
# https://stackoverflow.com/questions/66405794/not-authorized-to-perform-stsassumerolewithwebidentity-403
name = "${var.eks_cluster_name}-eks-efs"
tags = var.aws_tags
assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Federated" : format(
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:%s",
replace(
"${module.eks.cluster_oidc_issuer_url}",
"https://",
"oidc-provider/"
)
)
},
"Action" : "sts:AssumeRoleWithWebIdentity",
"Condition" : {
"StringEquals" : {
format(
"%s:sub",
trimprefix(
"${module.eks.cluster_oidc_issuer_url}",
"https://"
)
) : "system:serviceaccount:kube-system:efs-csi-controller-sa"
}
}
}
]
})
}
resource "aws_iam_policy" "efs" {
name = "${var.eks_cluster_name}-eks-efs"
tags = var.aws_tags
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"elasticfilesystem:*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "eks_efs_attach" {
role = aws_iam_role.eks_efs.name
policy_arn = aws_iam_policy.efs.arn
}