cloudposse / terraform-aws-ecs-container-definition

Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource
https://cloudposse.com/accelerate
Apache License 2.0
339 stars 244 forks source link

Error when trying to use EFS volumes in task/container definition #147

Closed tonyc-blastpoint closed 2 years ago

tonyc-blastpoint commented 3 years ago

Describe the Bug

I'm trying to use an EFS volume in an ECS service definition. The volumes variable is defined such that one has to supply a value for both the efs_volume_configuration and docker_volume_configuration parameters. This seems to be a Terraform syntax limitation having to do with a lack of optional arguments. However, the solution of passing an empty list doesn't work in this case, yielding the following error:

ClientException: When the volume parameter is specified, only one volume configuration type should be used.

Passing null for docker_volume_configuration doesn't work, either:

Error: Invalid dynamic for_each value

  on .terraform/modules/ecs-service/main.tf line 70, in resource "aws_ecs_task_definition" "default":
  70:         for_each = lookup(volume.value, "docker_volume_configuration", [])
    |----------------
    | volume.value is object with 4 attributes

Cannot use a null value in for_each.

Expected Behavior

To be able to use EFS volumes in an ECS service definition.

Steps to Reproduce

Update the example in examples/complete with the following added to main.tf:

  volumes = [{
    name = "html"
    host_path = "/usr/share/nginx/html"
    # docker_volume_configuration = null
    docker_volume_configuration = []
    efs_volume_configuration = [{
      file_system_id = "fs-8de214f2"
      root_directory          = "/home/user/www"
      transit_encryption      = "ENABLED"
      transit_encryption_port = 2999
      authorization_config = []
    }]
  }]

Environment (please complete the following information):

Terraform v0.14.10, MacOS 10.15.7 Anything that will help us triage the bug will help. Here are some ideas:

nitrocode commented 2 years ago

@tonyc-blastpoint I think this issue was created in the wrong repo.

https://github.com/cloudposse/terraform-aws-ecs-alb-service-task/blob/851ae54621f382208f9a576444116dc8cc4296b6/main.tf#L70-L71

Please open the issue in cloudposse/terraform-aws-ecs-alb-service-task repo

tonyc-blastpoint commented 2 years ago

Will do. I was told on the CloudPosse Slack to submit it here.

nitrocode commented 2 years ago

@tonyc-blastpoint it's a bit confusing so it may have been mistaken advice. If you recreate this issue in the other repo, it will be on the plate to be fixed. 😄

thanks for creating this issue because this does seem like a bug in the ecs alb service task module.