Skip to content

Commit

Permalink
Merge pull request #7 from 7Factor/jwood/sc-44056/support_efs_volumes
Browse files Browse the repository at this point in the history
Add support for efs volumes.
  • Loading branch information
dumptruckman authored Oct 13, 2023
2 parents 64138a5 + 9a867df commit 3e5fb8a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
33 changes: 33 additions & 0 deletions ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,39 @@ resource "aws_ecs_task_definition" "main_task" {
host_path = volume.value.host_path
}
}

dynamic "volume" {
for_each = [for v in var.efs_volumes : {
name = v.name
host_path = v.host_path
file_system_id = v.file_system_id
root_directory = v.root_directory
transit_encryption = v.transit_encryption
transit_encryption_port = v.transit_encryption_port
authorization_config = v.authorization_config
}]

content {
name = volume.value.name
host_path = volume.value.host_path

efs_volume_configuration {
file_system_id = volume.value.file_system_id
root_directory = volume.value.root_directory
transit_encryption = coalesce(volume.value.transit_encryption, volume.value.authorization_config != null ? "ENABLED" : "DISABLED")
transit_encryption_port = volume.value.transit_encryption_port

dynamic "authorization_config" {
for_each = [volume.value.authorization_config]

content {
access_point_id = authorization_config.value["access_point_id"]
iam = authorization_config.value["iam"]
}
}
}
}
}
}

resource "aws_ecs_service" "main_service" {
Expand Down
20 changes: 19 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ variable "volumes" {
description = "A list of definitions to attach volumes to the ECS task. Amazon does not allow empty volume names once declared, so defaulting to a dummy name if this var is left unused."
}

variable "efs_volumes" {
type = list(object({
name = string
host_path = optional(string)
file_system_id = string
root_directory = optional(string)
transit_encryption = optional(string)
transit_encryption_port = optional(number)
authorization_config = optional(object({
access_point_id = optional(string)
iam = optional(string)
}))
}))

default = []
description = "A list of definitions to attach EFS volumes to the ECS task. Name and file_system_id are required."
}

variable "task_role_arn" {
default = ""
description = "The arn of the iam role you wish to pass to the ecs task containers."
Expand Down Expand Up @@ -232,4 +250,4 @@ variable "lb_target_type" {
type = string
default = "instance"
description = "The target type of the LBs, needs to be set to IP for fargate"
}
}

0 comments on commit 3e5fb8a

Please # to comment.