diff --git a/module.tf b/module.tf index 8150812..279b0e5 100644 --- a/module.tf +++ b/module.tf @@ -22,6 +22,7 @@ variable "kubernetes" { annotations_fileType = optional(string) existing_pvc = optional(bool, false) mount_path = string + sub_path = optional(string) }))) environment = optional(map(object({ name = optional(string) @@ -65,9 +66,10 @@ variable "kubernetes" { } locals { - pvc_details = flatten([ + pvc_list = flatten([ for key, value in var.kubernetes : [ for index, pvc in value.pvc : { + key = "${coalesce(value.namespace, value.connected_namespace, key)}/${pvc.name}" index = index pvc = pvc.pvc name = pvc.name @@ -76,9 +78,24 @@ locals { storage_class_name = pvc.storage_class_name annotations_fileType = pvc.annotations_fileType existing_pvc = pvc.existing_pvc + sub_path = pvc.sub_path namespace = coalesce(value.namespace, value.connected_namespace, key) }] if value.enabled == true && value.pvc != null ]) + + # group duplicates instead of throwing an error + pvc_map_grouped = { + for p in local.pvc_list : + p.key => p... + } + + # keep only one PVC per key (take the first) + pvc_map = { + for k, list in local.pvc_map_grouped : + k => list[0] + } + + pvc_details = values(local.pvc_map) } locals { @@ -332,6 +349,7 @@ resource "kubernetes_deployment_v1" "automatic" { content { mount_path = volume_mount.value.mount_path name = "${volume_mount.value.name}-pvc" + sub_path = volume_mount.value.sub_path != null ? volume_mount.value.sub_path : "" } }