
resource "aws_service_discovery_service" "core_service_failover" {

  provider = aws.failover_region

  name = local.workspace["service_name"]

  dns_config {
    namespace_id = data.terraform_remote_state.mop_core_failover.outputs.ecs_private_discovery_namespace_id

    dns_records {
      ttl  = 10
      type = "A"
    }

    routing_policy = "MULTIVALUE"
  }

  health_check_custom_config {
    failure_threshold = 1
  }
}


module core_management_service_failover {

  providers = {
    aws = aws.failover_region
  }

  source = "git::ssh://git@bitbucket.org/netfoundry/nf-mop-tf.git//modules/aws/ecs_fargate_service"

  service_name = local.workspace["service_name"]
  container_count = local.workspace["failover_task_count"]
  task_definition = templatefile("${path.module}/templates/task-definition.json", local.core_management_failover_vars)
  task_role_arn = aws_iam_role.core_service_task_role.arn
  registry_arn = aws_service_discovery_service.core_service_failover.arn
  ecs_cluster_id = data.terraform_remote_state.mop_core_failover.outputs.ecs_cluster_id
  cpu = "2048"
  memory = "4096"
  execution_role_arn = aws_iam_role.core_service_task_role.arn
  security_groups = [
    aws_security_group.core_management_service_failover.id,
    aws_security_group.core_management_service_https_failover.id,
    data.terraform_remote_state.mop_core_failover.outputs.sg_alb_id
  ]
  subnets = data.terraform_remote_state.mop_core_failover.outputs.vpc_subnet_private_ids
  log_retention = 30

}