-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add efs filesystem and update copy images for lifecycle policy
- Loading branch information
Showing
2 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| # ------------------------------------------------------------------------------------- | ||
| # EKS-EFS - Creates an EFS volume and Kubernetes resources to use it | ||
| # ------------------------------------------------------------------------------------- | ||
| locals { | ||
| efs_access_points = [ | ||
| { | ||
| label = "data-logs" | ||
| name = "data-logs" | ||
| path = "/data_logs" | ||
| owner_uid = 51000 | ||
| owner_gid = 51000 | ||
| permissions = "755" | ||
| claim_name = "logs" | ||
| claim_namespace = "logs" | ||
| }, | ||
| { | ||
| label = "data-apps" | ||
| name = "data-apps" | ||
| path = "/data_apps" | ||
| owner_uid = 51000 | ||
| owner_gid = 51000 | ||
| permissions = "755" | ||
| claim_name = "apps" | ||
| claim_namespace = "apps" | ||
| }, | ||
| ] | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------------------------- | ||
| # EFS Namespace | ||
| # ------------------------------------------------------------------------------------- | ||
| resource "kubernetes_namespace" "efs_namespace" { | ||
| for_each = { for ap in local.efs_access_points : ap.label => ap } | ||
| metadata { | ||
| name = format("%v-%v", var.cluster_name, each.value.claim_namespace) | ||
| } | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------------------------- | ||
| # EFS Access Point | ||
| # ------------------------------------------------------------------------------------- | ||
| resource "aws_efs_access_point" "efs_ap" { | ||
| for_each = { for ap in local.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) }), | ||
| ) | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------------------------- | ||
| # EFS Persistent Volume | ||
| # ------------------------------------------------------------------------------------- | ||
| resource "kubernetes_persistent_volume" "efs_ap" { | ||
| for_each = { for ap in local.efs_access_points : ap.name => ap } | ||
| metadata { | ||
| name = format("efs-%v-pv", each.key) | ||
| } | ||
| spec { | ||
| capacity = { | ||
| storage = "1Gi" | ||
| } | ||
| claim_ref { | ||
| name = format("%v-%v-%v-claim", var.cluster_name, each.value.claim_namespace, 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) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| # ------------------------------------------------------------------------------------- | ||
| # EFS Persistent Volume Claim Per AP | ||
| # ------------------------------------------------------------------------------------- | ||
| resource "kubernetes_persistent_volume_claim" "efs_ap" { | ||
| for_each = { for ap in local.efs_access_points : ap.name => ap } | ||
| metadata { | ||
| name = format("%v-%v-%v-claim", var.cluster_name, each.value.claim_namespace, 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] | ||
| } | ||
|
|
||
| # ------------------------------------------------------------------------------------- | ||
| # EFS Persistent Volume Base Claim | ||
| # ------------------------------------------------------------------------------------- | ||
| resource "kubernetes_persistent_volume_claim" "pvc_efs-cluster-base" { | ||
| depends_on = [kubernetes_storage_class.efs-sc] | ||
| metadata { | ||
| name = format("%v%v-%v", "eks-", var.cluster_name, "base-claim") | ||
| } | ||
| wait_until_bound = false | ||
| spec { | ||
| access_modes = ["ReadWriteMany"] | ||
| resources { | ||
| requests = { | ||
| storage = "25Gi" | ||
| } | ||
| } | ||
| storage_class_name = "efs" | ||
| } | ||
| } | ||
|
|
||
| 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 | ||
| ## # | ||
| ## |