resource "aws_ecs_task_definition" "uptime" {
  family                   = "acdl-uptime"
  cpu                      = tostring(var.cpu)
  memory                   = tostring(var.memory)
  requires_compatibilities = ["FARGATE"]
  network_mode             = "awsvpc"
  container_definitions    = local.container_definitions
}

resource "aws_ecs_service" "uptime" {
  name            = "acdl-uptime"
  cluster         = local.cluster_ref
  task_definition = aws_ecs_task_definition.uptime.arn
  desired_count   = var.feature_flag_enabled ? 1 : 0
  launch_type     = "FARGATE"

  dynamic "network_configuration" {
    for_each = length(local.subnet_list) > 0 ? [1] : []
    content {
      subnets          = local.subnet_list
      security_groups  = local.sg_list
      assign_public_ip = true
    }
  }
}