Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFS volumes (efs_volume_configuration or docker_volume_configuration) doesn't work with trussworks/terraform-aws-ecs-service v.6.6.0 using the module #330

Open
PhungV0 opened this issue Nov 8, 2022 · 1 comment

Comments

@PhungV0
Copy link

PhungV0 commented Nov 8, 2022

Describe the bug
EFS volumes (efs_volume_configuration or docker_volume_configuration) doesn't work with trussworks/terraform-aws-ecs-service v.6.6.0 using the module. I need to modify locally the ecs module main.tf and variables.tf and disable some unnecessary rows to make it happen.

AWS CLI version: aws-cli/2.2.38
terraform v1.3.4
module "ecs-service" {
source = "trussworks/ecs-service/aws"
version ="6.6.0"

When using the ecs module, you can find from main.tf

dynamic "volume" {
for_each = var.container_volumes
content {
name = volume.value.name
}
}
and from variables.tf

variable "container_volumes" {
description = "Volumes that containers in your task may use."
default = []
type = list(
object({
name = string
})
)
}

So basically as default you can add only the name for container_volumes without any efs_volume_configuration or docker_volume_configuration

I need to modify locally main.tf and add extra information to enable mapping the efs volume configuration for ECS

dynamic "volume" {
for_each = var.container_volumes
content {
name = volume.value.name

  # host_path = lookup(volume.value, "host_path", null)

  # dynamic "docker_volume_configuration" {
  #   for_each = lookup(volume.value, "docker_volume_configuration", [])
  #   content {
  #     autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
  #     driver        = lookup(docker_volume_configuration.value, "driver", null)
  #     driver_opts   = lookup(docker_volume_configuration.value, "driver_opts", null)
  #     labels        = lookup(docker_volume_configuration.value, "labels", null)
  #     scope         = lookup(docker_volume_configuration.value, "scope", null)
  #   }
  # }

  dynamic "efs_volume_configuration" {
    for_each = lookup(volume.value, "efs_volume_configuration", [])
    content {
      file_system_id          = lookup(efs_volume_configuration.value, "file_system_id", null)
      root_directory          = lookup(efs_volume_configuration.value, "root_directory", null)
      # transit_encryption      = lookup(efs_volume_configuration.value, "transit_encryption", null)
      # transit_encryption_port = lookup(efs_volume_configuration.value, "transit_encryption_port", null)
      # dynamic "authorization_config" {
      #   for_each = lookup(efs_volume_configuration.value, "authorization_config", [])
      #   content {
      #     access_point_id = lookup(authorization_config.value, "access_point_id", null)
      #     iam             = lookup(authorization_config.value, "iam", null)
      #   }
      # }
    }
  }
}

}

and then add to variables.tf

variable "container_volumes" {
description = "Volumes that containers in your task may use."
type = list(object({
#host_path = string
name = string
# docker_volume_configuration = list(object({
# autoprovision = bool
# driver = string
# driver_opts = map(string)
# labels = map(string)
# scope = string
# }))
efs_volume_configuration = list(object({
file_system_id = string
root_directory = string
# transit_encryption = string
# transit_encryption_port = string
# authorization_config = list(object({
# access_point_id = string
# iam = string
# }))
}))
}))
default = []
}

@PhungV0
Copy link
Author

PhungV0 commented Oct 10, 2023

Hi,
This is how I got the ECS EFS/docker/FSx volume configuration working at the same time with ECS. Are u able to verify and update the module codes? Thanks.

-- variables.tf
variable "container_volumes" {
description = "Volumes that containers in your task may use."
default = {}
type = any
}

-- main.tf / I have disabled some values from efs_volume_configuration, because I don't need it
dynamic "volume" {
for_each = var.container_volumes
content {
name = volume.value.name

  host_path = lookup(volume.value, "host_path", null)

  dynamic "docker_volume_configuration" {
    for_each = lookup(volume.value, "docker_volume_configuration", [])
     content {
       autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
       driver        = lookup(docker_volume_configuration.value, "driver", null)
       driver_opts   = lookup(docker_volume_configuration.value, "driver_opts", null)
       labels        = lookup(docker_volume_configuration.value, "labels", null)
       scope         = lookup(docker_volume_configuration.value, "scope", null)
     }
   }

  dynamic "efs_volume_configuration" {
    for_each = lookup(volume.value, "efs_volume_configuration", [])
    content {
      file_system_id          = lookup(efs_volume_configuration.value, "file_system_id", null)
      root_directory          = lookup(efs_volume_configuration.value, "root_directory", null)
      # transit_encryption      = lookup(efs_volume_configuration.value, "transit_encryption", null)
      # transit_encryption_port = lookup(efs_volume_configuration.value, "transit_encryption_port", null)
      # dynamic "authorization_config" {
      #   for_each = lookup(efs_volume_configuration.value, "authorization_config", [])
      #   content {
      #     access_point_id = lookup(authorization_config.value, "access_point_id", null)
      #     iam             = lookup(authorization_config.value, "iam", null)
      #   }
      # }
    }
  }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant