@@ -23,13 +23,8 @@ locals {
2323 volumes = try (local. resource_properties . volumes , {})
2424 restart_policy = try (local. resource_properties . restartPolicy , null )
2525
26- # Connections - Extract secret connections from Radius.Security/secrets resources
26+ # Connections - used for linked resources like persistent volumes
2727 connections = try (var. context . resource . connections , {})
28- secret_connections = {
29- for name , conn in local . connections : name => conn
30- if try (conn. status . computedValues . secretName , null ) != null
31- }
32- secret_names = [for name , conn in local . secret_connections : conn . status . computedValues . secretName ]
3328
3429 # Replica count - use from properties or default to 1
3530 replica_count = try (local. resource_properties . replicas , 1 )
@@ -94,10 +89,17 @@ locals {
9489
9590 # Volume mounts
9691 volume_mounts = [
97- for vm in try (config. volumeMounts , []) : {
98- name = vm . volumeName
99- mount_path = vm . mountPath
100- }
92+ for vm in try (config. volumeMounts , []) : merge (
93+ {
94+ name = vm.volumeName
95+ mount_path = vm.mountPath
96+ },
97+ try (vm. subPath , null ) != null ? { sub_path = vm.subPath } : {},
98+ try (vm. readOnly , null ) != null ? { read_only = vm.readOnly } : {},
99+ try (vm. readOnly , null ) == null && try (local. volumes [vm . volumeName ]. persistentVolume . accessMode , " " ) != " " && lower (local. volumes [vm . volumeName ]. persistentVolume . accessMode ) == " readonlymany" ? {
100+ read_only = true
101+ } : {}
102+ )
101103 ]
102104
103105 # Resources - Transform memoryInMib to memory format
@@ -150,10 +152,17 @@ locals {
150152
151153 # Volume mounts
152154 volume_mounts = [
153- for vm in try (config. volumeMounts , []) : {
154- name = vm . volumeName
155- mount_path = vm . mountPath
156- }
155+ for vm in try (config. volumeMounts , []) : merge (
156+ {
157+ name = vm.volumeName
158+ mount_path = vm.mountPath
159+ },
160+ try (vm. subPath , null ) != null ? { sub_path = vm.subPath } : {},
161+ try (vm. readOnly , null ) != null ? { read_only = vm.readOnly } : {},
162+ try (vm. readOnly , null ) == null && try (local. volumes [vm . volumeName ]. persistentVolume . accessMode , " " ) != " " && lower (local. volumes [vm . volumeName ]. persistentVolume . accessMode ) == " readonlymany" ? {
163+ read_only = true
164+ } : {}
165+ )
157166 ]
158167
159168 # Resources - Transform memoryInMib to memory format
@@ -180,9 +189,15 @@ locals {
180189 name = vol_name
181190
182191 # Persistent Volume Claim
183- persistent_volume_claim = try (vol_config. persistentVolume , null ) != null ? {
184- claim_name = vol_config.persistentVolume.claimName
185- } : null
192+ persistent_volume_claim = try (vol_config. persistentVolume , null ) != null ? (
193+ try (vol_config. persistentVolume . claimName , " " ) != " " ? {
194+ claim_name = vol_config.persistentVolume.claimName
195+ } : (
196+ try (local. connections [vol_name ]. status . computedValues . claimName , " " ) != " " ? {
197+ claim_name = local.connections[vol_name].status.computedValues.claimName
198+ } : null
199+ )
200+ ) : null
186201
187202 # Secret
188203 secret = try (vol_config. secret , null ) != null ? {
@@ -326,22 +341,14 @@ resource "kubernetes_deployment" "deployment" {
326341 }
327342 }
328343
329- # Environment variables from connected secrets (Radius.Security/secrets)
330- dynamic "env_from" {
331- for_each = local. secret_names
332- content {
333- secret_ref {
334- name = env_from. value
335- }
336- }
337- }
338-
339344 # Volume mounts
340345 dynamic "volume_mount" {
341346 for_each = init_container. value . volume_mounts
342347 content {
343348 name = volume_mount. value . name
344349 mount_path = volume_mount. value . mount_path
350+ sub_path = try (volume_mount. value . sub_path , null )
351+ read_only = try (volume_mount. value . read_only , null )
345352 }
346353 }
347354
@@ -407,22 +414,14 @@ resource "kubernetes_deployment" "deployment" {
407414 }
408415 }
409416
410- # Environment variables from connected secrets (Radius.Security/secrets)
411- dynamic "env_from" {
412- for_each = local. secret_names
413- content {
414- secret_ref {
415- name = env_from. value
416- }
417- }
418- }
419-
420417 # Volume mounts
421418 dynamic "volume_mount" {
422419 for_each = container. value . volume_mounts
423420 content {
424421 name = volume_mount. value . name
425422 mount_path = volume_mount. value . mount_path
423+ sub_path = try (volume_mount. value . sub_path , null )
424+ read_only = try (volume_mount. value . read_only , null )
426425 }
427426 }
428427
0 commit comments