From e76e0cd79f89d0993e1f479d79d09bf6a2eaf5b6 Mon Sep 17 00:00:00 2001 From: Matt Drees Date: Sat, 4 Jul 2020 15:04:46 -0600 Subject: [PATCH] Add non-persistent volume support This adds a 'volumes' variable that can drive the 'volume' nested config block. For now, we'll only add support for non-persistent volumes, but this can be easily changed later on. --- examples/complete/main.tf | 4 ++++ main.tf | 9 +++++++++ variables.tf | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 0625d1f..533a33c 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -40,6 +40,10 @@ module "ecs_scheduled_task" { create_ecs_task_execution_role = false ecs_task_execution_role_arn = aws_iam_role.ecs_task_execution.arn + volumes = [{ + name = "example-volume" + }] + tags = { Environment = "prod" } diff --git a/main.tf b/main.tf index a1256da..aa69e88 100644 --- a/main.tf +++ b/main.tf @@ -147,6 +147,15 @@ resource "aws_ecs_task_definition" "default" { # https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#network_mode network_mode = "awsvpc" + # The docker volumes that the task will make available to its containers. + # https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#volumes + dynamic "volume" { + for_each = var.volumes + content { + name = volume.key.name + } + } + # A mapping of tags to assign to the resource. tags = merge({ "Name" = var.name }, var.tags) } diff --git a/variables.tf b/variables.tf index e37086a..b135d8f 100644 --- a/variables.tf +++ b/variables.tf @@ -118,3 +118,11 @@ variable "ecs_task_execution_role_arn" { type = string description = "The ARN of the ECS Task Execution IAM Role." } + +variable "volumes" { + default = [] + type = set(object({ + name = string + })) + description = "The non-persistent data volumes to be used by the task." +}