/*
data "aws_ecr_repository" "nginx" {
  name = "nginx"

  provider = aws.gdb-apollo-dev
}

module "nginx_options_task_def" {
  source = "../../../modules/ecs/tasks/fargate_v3"

  env_prefix      = local.env_prefix
  project_group   = local.project_group
  family          = "${local.env_prefix}-${local.project_group}-nginx-options"
  container_name  = "nginx"
  container_image = "${data.aws_ecr_repository.nginx.repository_url}:1.18.0-alpine"
  cpu             = 256
  memory          = 512

  awslogs_retention = module.cloudwatch_logs_retention_by_env[local.env_prefix]

  task_role_arn = data.aws_iam_role.standard_exec.arn
  exec_role_arn = data.aws_iam_role.standard_exec.arn

  port_mappings = [
    {
      containerPort = 8000
      hostPort      = 8000
      protocol      = "tcp"
    },
  ]

  common_tags = merge(
    local.common_tags,
    {
      project                  = "Portal",
      service                  = "ECS",
      plat_env_project_service = "${local.aggregated_tag}_PRL_ECS"
    }
  )
}

module "nginx_options_service" {
  source = "../../../modules/ecs/services/service_taskless_v2"

  env_prefix    = local.env_prefix
  project       = "nginx-options"
  project_group = local.project_group

  cluster_arn   = data.aws_ecs_cluster.main.arn
  desired_count = 1

  security_groups = [data.aws_security_group.ecs.id]
  subnets         = data.aws_subnets.private_subnets.ids
  vpc_id          = data.aws_vpc.main.id

  task_definition_arn = module.nginx_options_task_def.arn

  alb_enabled             = true
  https_listener_arn      = data.aws_lb_listener.external_https_listener.arn
  tg_health_check_path    = "/_health"
  tg_health_check_matcher = "200"
  container_port          = 8000
  container_name          = "nginx"
  url                     = "nginx.apollo.local" // fake name

  enable_ecs_managed_tags = true

  common_tags = merge(
    local.common_tags,
    {
      project                  = "Portal",
      service                  = "ECS",
      plat_env_project_service = "${local.aggregated_tag}_PRL_ECS"
    }
  )
}

resource "aws_lb_listener_rule" "handle_options" {
  listener_arn = data.aws_lb_listener.external_https_listener.arn

  priority = 1 // has to be the first rule

  action {
    type             = "forward"
    target_group_arn = module.nginx_options_service.tg_arn
  }
  condition {
    http_request_method {
      values = ["OPTIONS"]
    }
  }
}
*/
