-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstorages.tf
68 lines (56 loc) · 1.52 KB
/
storages.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
locals {
storage_subnets = { for index, zone in local.private_subnets : "zone${index}" => local.private_subnets[index] }
}
resource "aws_efs_file_system" "efs_file_system" {
encrypted = true
tags = var.tags
}
data "aws_iam_policy_document" "policy" {
statement {
sid = "EfsPolicy"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"elasticfilesystem:ClientMount",
"elasticfilesystem:ClientWrite",
"elasticfilesystem:CreateAccessPoint",
"elasticfilesystem:TagResource",
]
resources = [aws_efs_file_system.efs_file_system.arn]
condition {
test = "Bool"
variable = "aws:SecureTransport"
values = ["true"]
}
}
}
resource "aws_efs_file_system_policy" "policy" {
file_system_id = aws_efs_file_system.efs_file_system.id
policy = data.aws_iam_policy_document.policy.json
}
resource "aws_efs_mount_target" "mount_target" {
for_each = local.storage_subnets
file_system_id = aws_efs_file_system.efs_file_system.id
subnet_id = each.value
security_groups = [module.eks.cluster_primary_security_group_id]
}
resource "kubernetes_storage_class_v1" "efs" {
metadata {
name = "efs"
}
storage_provisioner = "efs.csi.aws.com"
parameters = {
provisioningMode = "efs-ap" # Dynamic provisioning
fileSystemId = aws_efs_file_system.efs_file_system.id
directoryPerms = "700"
}
mount_options = [
"iam"
]
depends_on = [
module.k8s_eks_addons
]
}