terraform-aws-ecs icon indicating copy to clipboard operation
terraform-aws-ecs copied to clipboard

Dynamically add container(s) to container_definitions

Open nbcchen opened this issue 1 year ago β€’ 1 comments

Is your request related to a new offering from AWS?

Is this functionality available in the AWS provider for Terraform? See CHANGELOG.md, too.

  • No πŸ›‘: please wait to file a request until the functionality is avaialble in the AWS provider
  • Yes βœ…: please list the AWS provider version which introduced this functionality

Is your request related to a problem? Please describe.

Add container based on condition

Describe the solution you'd like.

container_definitions = {
  app = {
    image = "..."
  }
}

additional_containers = flatten(var.create_sidecar ? [
  {
    image = "..."
  }
]: [])

Describe alternatives you've considered.

Additional context

nbcchen avatar Nov 02 '24 15:11 nbcchen

You can achieve this using a locals or dynamic block

container_definitions = { nginx = { image = "nginx:latest" port_mappings = [ { protocol = "tcp", containerPort = 80 } ] environment = [ { name = "ENV", value = var.environment } ] }, aws-otel-collector = { image = "public.ecr.aws/aws-observability/aws-otel-collector:v0.40.2", port_mappings = [ { "containerPort" : 2000, "protocol" : "udp" } ] }, appconfig-agent = { image = "public.ecr.aws/aws-appconfig/aws-appconfig-agent:2.x", port_mappings = [ { "containerPort" : 2772, "protocol" : "tcp" } ] } }

container_definitions = local.container_definitions

pauljflo avatar Feb 26 '25 12:02 pauljflo

This issue has been resolved in version 6.0.0 :tada:

antonbabenko avatar Jul 07 '25 12:07 antonbabenko

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Aug 07 '25 02:08 github-actions[bot]