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

The port_mappings variable needs to include the "name" parameter to support Service Connect integration. #162

Closed ckonefke closed 12 months ago

ckonefke commented 1 year ago

Describe the Feature

I was trying to use a container definition created with this module with an ECS fargate service that includes Service Connect for cross service communication. The Service Connect setup requires a reference to a named port mapping from the container that will be used. From what I can see, there's currently no way to define the name parameter for a containers port mapping.

Expected Behavior

I attempted to add the "name" parameter to the port mapping with a block like this... port_mappings = [ { name = "http-80-tcp" containerPort = 80 hostPort = 80 protocol = "tcp" }, ]

The mapping was successfully setup, but the "name" parameter was ignored since it's missing from the variable definition. https://github.com/cloudposse/terraform-aws-ecs-container-definition/blob/main/variables.tf#L29

Use Case

I need a named port mapping to successfully configure Service Connect in our environment. I'm currently trying to find a workaround, but this should be a fairly easy fix.

Describe Ideal Solution

The "name" parameter would be added as an option entry in the port_mappings setting. That way the container would have a properly named port map that could be referred to by the Service Connect setup.

Alternatives Considered

I believe that it's just a matter of adding the "name" parameter as an optional setting for the port_mappings variable variable "port_mappings" { type = list(object({ name = optional(string) containerPort = number hostPort = number protocol = string }))

Additional Context

No response