Skip to content

Commit f08194d

Browse files
authored
Merge pull request #1 from springload/add/dynamic-volume
Add conditional volume block for task definition
2 parents 179cf0b + 94078ad commit f08194d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ resource "aws_ecs_task_definition" "task" {
2828
portMappings = local.balanced && local.load_balancer_container_name == s.name ? coalescelist(var.port_mappings, local.defaultPortMappings) : []
2929
})])
3030

31+
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 = efs_vol.root_dir ? efs_vol.root_dir : "/opt/data"
36+
}]
37+
38+
content {
39+
name = volume.value.name
40+
efs_volume_configuration {
41+
file_system_id = volume.value.efs_id
42+
root_directory = volume.value.root_directory
43+
}
44+
}
45+
}
46+
3147
task_role_arn = var.task_role_arn
3248

3349
# the /tmp volume is needed if the root fs is readonly

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ variable "user" {
115115
default = ""
116116
}
117117

118+
variable "efs_volumes" {
119+
description = "Optional list of efs volumes, which are a map with {efs_id:, root_dir:}"
120+
type = list(map(string))
121+
default = {}
122+
}
118123

119124
locals {
120125
balanced = var.container_port > 0

0 commit comments

Comments
 (0)