locals {

  integration_example_env_vars = [
    {
      name  = "ATLAS_BEARER_TOKEN_COOKIE_NAME",
      value = "dna_bearer_token_${local.env_prefix}"
    },
    {
      name  = "ATLAS_REFRESH_TOKEN_COOKIE_NAME",
      value = "dna_refresh_token_${local.env_prefix}"
    },
  ]

}

data "aws_ecr_repository" "integration_example" {
  name = "core/atlas-um-integration-example"
}

module "integration_example_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}-integration-example"
  container_name    = "integration-example"
  container_image   = "${data.aws_ecr_repository.integration_example.repository_url}:${local.docker_image_env_tag[local.env_prefix]}"
  cpu               = 512
  memory            = 1024
  awslogs_retention = 180

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

  env_vars = local.integration_example_env_vars


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

  common_tags = merge(
    local.common_tags,
    {
      project                  = "User Management",
      service                  = "ECS",
      plat_env_project_service = "${local.aggregated_tag}_UM_ECS"
    }
  )
}
/*
module "integration_example_service" {
  source = "../../../modules/ecs/services/service_taskless_v2"

  env_prefix    = local.env_prefix
  project       = "integration-example"
  project_group = local.project_group

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

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

  route53_zone_id = data.aws_route53_zone.default.zone_id
  alb_dns_name    = data.aws_lb.external_alb.dns_name
  alb_zone_id     = data.aws_lb.external_alb.zone_id

  task_definition_arn = module.integration_example_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
  url                     = module.domains[local.env_prefix]["atlas-um-example"]

  enable_ecs_managed_tags = true

  common_tags = merge(
    local.common_tags,
    {
      project                  = "User Management",
      service                  = "ECS",
      plat_env_project_service = "${local.aggregated_tag}_UM_ECS"
    }
  )
}

resource "aws_route53_record" "integration_example_apollo_record" {
  zone_id = data.aws_route53_zone.apollo_stream_zone.zone_id
  name    = "${local.env_prefix}-integration-example.apollo.stream"
  type    = "A"

  alias {
    name                   = data.aws_lb.external_alb.dns_name
    zone_id                = data.aws_lb.external_alb.zone_id
    evaluate_target_health = false
  }

  provider = aws.gdb-delphi-dev
}

resource "aws_route53_record" "integration_example_insights_record" {
  zone_id = data.aws_route53_zone.insights_stream_zone.zone_id
  name    = "${local.env_prefix}-integration-example.insights.stream"
  type    = "A"

  alias {
    name                   = data.aws_lb.external_alb.dns_name
    zone_id                = data.aws_lb.external_alb.zone_id
    evaluate_target_health = false
  }

  provider = aws.gdb-artistapp-prod
}

resource "aws_alb_listener_rule" "integration_example_insights_listener_rule" {
  listener_arn = data.aws_lb_listener.external_https_listener.arn

  action {
    type             = "forward"
    target_group_arn = module.integration_example_service.tg_arn
  }

  condition {
    host_header {
      values = [
        aws_route53_record.integration_example_apollo_record.name,
        aws_route53_record.integration_example_insights_record.name,
      ]
    }
  }
}
*/
