Skip to content

Commit c7d5540

Browse files
author
Benjamin Wattie
committed
add volumes into mount points too
1 parent 3fc9d05 commit c7d5540

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

main.tf

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resource "aws_ecs_task_definition" "task" {
88
essential = var.essential
99
memory = var.memory
1010
memoryReservation = var.memory_reservation
11-
mountPoints = var.readonlyRootFilesystem ? [{ sourceVolume = "tmp", containerPath = "/tmp" }] : []
11+
mountPoints = local.task_def_all_mount_points
1212
volumesFrom = []
1313
linuxParameters = {
1414
initProcessEnabled = var.init_process_enabled
@@ -29,11 +29,7 @@ resource "aws_ecs_task_definition" "task" {
2929
})])
3030

3131
dynamic "volume" {
32-
for_each = [for efs_vol in var.efs_volumes : {
33-
name = "${var.cluster_name}-${efs_vol.efs_id}"
34-
efs_id = efs_vol.efs_id
35-
root_directory = lookup(efs_vol, "root_dir", "/opt/data")
36-
}]
32+
for_each = local.task_def_efs_volumes
3733

3834
content {
3935
name = volume.value.name
@@ -89,3 +85,19 @@ resource "aws_ecs_service" "service" {
8985
}
9086
}
9187

88+
locals {
89+
task_def_ro_mount_points = var.readonlyRootFilesystem ? [{ sourceVolume = "tmp", containerPath = "/tmp" }] : []
90+
91+
task_def_efs_volumes = [for efs_vol in var.efs_volumes : {
92+
name = "${var.cluster_name}-${efs_vol.efs_id}"
93+
efs_id = efs_vol.efs_id
94+
root_directory = lookup(efs_vol, "root_dir", "/mnt/efs")
95+
}]
96+
97+
task_def_efs_mount_points = [for efs_vol in var.efs_volumes : {
98+
sourceVolume = "${var.cluster_name}-${efs_vol.efs_id}"
99+
containerPath = lookup(efs_vol, "container_path", "/private_storage")
100+
}]
101+
102+
task_def_all_mount_points = concat(local.task_def_ro_mount_points, local.task_def_efs_mount_points)
103+
}

0 commit comments

Comments
 (0)