diff --git a/examples/efs-persistent-volumes/efs-access-points.tf b/examples/efs-persistent-volumes/efs-access-points.tf new file mode 100644 index 0000000..c083dc0 --- /dev/null +++ b/examples/efs-persistent-volumes/efs-access-points.tf @@ -0,0 +1,83 @@ +resource "aws_efs_access_point" "efs_ap" { + for_each = { for ap in var.efs_access_points : ap.name => ap } + file_system_id = module.efs.id + root_directory { + path = each.value.path + creation_info { + owner_uid = each.value.owner_uid + owner_gid = each.value.owner_gid + permissions = each.value.permissions + } + } + + tags = merge( + local.base_tags, + local.common_tags, + var.application_tags, + tomap({ "Name" = format("%v-efs-access-point_%v", var.cluster_name, each.key) }), + ) +} + +resource "kubernetes_persistent_volume" "efs_ap" { + for_each = { for ap in var.efs_access_points : ap.name => ap } + metadata { + name = format("efs-%v-pv", each.key) + } + spec { + capacity = { + storage = "1Gi" + } + claim_ref { + name = format("%v-%v-claim", var.cluster_name, each.key) + namespace = format("%v-%v", var.cluster_name, each.value.claim_namespace) + } + access_modes = ["ReadWriteMany"] + persistent_volume_reclaim_policy = "Retain" + volume_mode = "Filesystem" + storage_class_name = "efs" + persistent_volume_source { + csi { + driver = "efs.csi.aws.com" + volume_handle = format("%v:%v:%v", module.efs.id, "", aws_efs_access_point.efs_ap[each.key].id) + } + } + } +} + +resource "kubernetes_persistent_volume_claim" "efs_ap" { + for_each = { for ap in var.efs_access_points : ap.name => ap } + metadata { + name = format("%v-%v-claim", var.cluster_name, each.key) + namespace = format("%v-%v", var.cluster_name, each.value.claim_namespace) + } + wait_until_bound = false + spec { + access_modes = ["ReadWriteMany"] + storage_class_name = "efs" + resources { + requests = { + storage = "1Gi" + } + } + } + depends_on = [kubernetes_persistent_volume.efs_ap] +} + +output "efs_ap_ids" { + description = "EFS AccessPoint IDs" + value = { for k, v in aws_efs_access_point.efs_ap : k => v.id } +} + +## # apiVersion: v1 +## # kind: PersistentVolumeClaim +## # metadata: +## # name: ditd-gups-dev1-data1-geoserver-claim +## # spec: +## # accessModes: +## # - ReadWriteMany +## # storageClassName: efs-sc +## # resources: +## # requests: +## # storage: 5Gi +## # +## diff --git a/examples/efs-persistent-volumes/variables.efs-access-points.tf b/examples/efs-persistent-volumes/variables.efs-access-points.tf new file mode 100644 index 0000000..e03280e --- /dev/null +++ b/examples/efs-persistent-volumes/variables.efs-access-points.tf @@ -0,0 +1,13 @@ +variable "efs_access_points" { + description = "List of objects for creating EFS accesspoints and PV/PVCs" + type = list(object({ + name = string + path = string + owner_uid = number + owner_gid = number + permissions = string + claim_name = string + claim_namespace = string + })) + default = [] +}