Skip to content

port_mappings are always empty #151

@allexivan

Description

@allexivan

Description

When I try to create a new container definition, the port_mapping are always empty.

  • [X ] ✋ I have searched the open/closed issues and my issue is not listed.

Versions

  • Module version [Required]:
    5.7.3

  • Terraform version:
    Terraform v1.6.6
    on darwin_arm64

  • Provider version(s):

  • provider registry.terraform.io/hashicorp/aws v5.31.0
  • provider registry.terraform.io/hashicorp/random v3.6.0

Reproduction Code [Required]

Steps to reproduce the behavior:

module "ecs_container_definition" {
  source  = "terraform-aws-modules/ecs/aws//modules/container-definition"
  version = "~> 5.7.3"

  for_each = var.ecs_services

  name   = each.value["ecs_task_container_name"]
  cpu    = each.value["ecs_task_cpu"]
  memory = each.value["ecs_task_memory"]

  environment = each.value["environment"]
  secrets     = each.value["secrets"]
  essential   = true
  image       = "ar-public-maintenance"

  port_mappings = [
    {
      name          = each.value["ecs_task_container_name"]
      containerPort = each.value["ecs_task_container_port"]
      hostPort      = each.value["ecs_task_host_port"]
      protocol      = each.value["ecs_task_protocol"]
    }
  ]

  readonly_root_filesystem = each.value["ecs_task_readonly_root_filesystem"]

  enable_cloudwatch_logging = true
  log_configuration = {
    cloud_watch_log_group_name = "${var.prefix}-${var.environment}-${each.key}-task-log-group"
  }

  memory_reservation = each.value["ecs_task_memory"]

  tags = {
    Environment = var.environment
    Terraform   = "true"
  }
}

output "ecs_container_definitions" {
description = "Container definitions for each ECS service"
value = { for svc_name, def in module.ecs_container_definition : svc_name => def.container_definition }
}

Expected behavior

In AWS task definition:


{
    "taskDefinitionArn": "arn here",
    "containerDefinitions": [
        {
            "name": "demo",
            "image": "ar-public-maintenance",
            "cpu": 128,
            "memory": 256,
            "memoryReservation": 256,
            "portMappings": [
                {
                    "name": "demo",
                    "containerPort": 80,
                    "hostPort": 80,
                    "protocol": "tcp"
                }
            ],

Actual behavior

In AWS task definition:

{
    "taskDefinitionArn": "arn here",
    "containerDefinitions": [
        {
            "name": "demo",
            "image": "ar-public-maintenance",
            "cpu": 128,
            "memory": 256,
            "portMappings": [],
}

Terminal Output Screenshot(s)

Changes to Outputs:
  + ecs_container_definitions                 = {
      + app-backend = {
          + cpu                    = 128
          + environment            = [
              + {
                  + name  = "APP_ENV"
                  + value = "STAGING"
                },
              + {
                  + name  = "METRICS_PORT"
                  + value = "9091"
                },
              + {
                  + name  = "BULL_BOARD_PORT"
                  + value = "7071"
                },
              + {
                  + name  = "NODE_ENV"
                  + value = "production"
                },
            ]
          + essential              = true
          + image                  = "ar-public-maintenance"
          + interactive            = false
          + linuxParameters        = {
              + initProcessEnabled = false
            }
          + logConfiguration       = {
              + cloud_watch_log_group_name = "backend-task-log-group"
              + logDriver                  = "awslogs"
              + options                    = {
                  + awslogs-group         = "/aws/ecs//demo"
                  + awslogs-region        = "us-west-2"
                  + awslogs-stream-prefix = "ecs"
                }
            }
          + memory                 = 256
          + memoryReservation      = 256
          + mountPoints            = []
          + name                   = "demo"
          + portMappings           = [
              + {
                  + containerPort = 80
                  + hostPort      = 80
                  + name          = "demo"
                  + protocol      = "tcp"
                },
            ]
          + privileged             = false
          + pseudoTerminal         = false
          + readonlyRootFilesystem = false
          + secrets                = [
              + {
                  + name      = "AR_CORE_API_URL"
                  + valueFrom = ""
                },
            ]
          + startTimeout           = 30
          + stopTimeout            = 120
          + volumesFrom            = []
        }
    }

Additional context

Similar issue as this one:

#122

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions