module "stripo_screenshot_service" {
  source = "git@github.com:theorchard/terraform-fargate.git//?ref=6.1.1"

  providers = {
    aws.dns = aws
  }

  environment                              = var.environment
  service_name                             = "${var.service_name}-screenshot-service"
  aws_region                               = var.aws_region
  application_family                       = var.application_family
  service_platform_version                 = "1.4.0"
  deployment_minimum_healthy_percent       = "100"
  desired_task_count                       = 1
  minimum_capacity                         = 1
  maximum_capacity                         = 1
  task_cpu                                 = 512
  task_memory                              = 1024
  container_port                           = 8080
  health_check_grace_period_seconds        = 300
  health_check_path                        = "/version"
  override_route53_zone_id                 = data.aws_route53_zone.route53_zone.id
  load_balancer_access_logs_s3_bucket_name = var.load_balancer_logs_bucket
  vpc_id                                   = module.vpc_info.vpc_id
  fargate_service_subnets                  = module.vpc_info.default_private_subnet_ids
  load_balancer_subnets                    = module.vpc_info.default_private_subnet_ids
  non_ecr_image                            = "086679231553.dkr.ecr.us-east-1.amazonaws.com/stripo/screenshot-service:1.175.0"
  custom_waf_arn                           = module.stripo_waf.waf_blocking_arn_output
  https_listener_certificate_id            = var.https_listener_certificate_id
  iam_managed_policy_attachments = [
    module.efs_volume.efs_iam_policy_arn_output,
  ]

  docker_volumes = [
    {
      name            = "${var.environment}-${var.service_name}"
      file_system_id  = module.efs_volume.efs_file_system_id_output
      access_point_id = module.efs_volume.efs_access_point_id_output
    }
  ]
  docker_volume_mount_points = [
    {
      source_volume  = "${var.environment}-${var.service_name}"
      container_path = var.screenshot_service_efs_volume_container_path
    }
  ]

  environment_variables = [
    {
      Environment = var.environment
    },
    {
      APPLICATION_ENV = "${var.environment}"
    },
    {
      DD_TRACE_ANALYTICS_ENABLED = "true"
    },
    {
      DD_TRACE_APP_NAME = "${var.environment}-${var.service_name}"
    },
    {
      APPNAME = "screenshot-service"
    },
    {
      ENV = "PLUGINS"
    },
    {
      PROFILE = "PLUGINS"
    },
    {
      NODE_MEMORY = "512"
    }
  ]
}

module "screenshot_service_dashboard" {
  source                            = "git@github.com:theorchard/terraform-datadog.git//modules/service?ref=6.10.7"
  environment                       = var.environment
  environment_type                  = "fargate"
  service_name                      = "${var.service_name}-screenshot-service"
  application_family                = var.application_family
  notification_endpoints            = var.application_alert_channel
  escalation_notification_endpoints = var.application_alert_channel
  teams                             = ["fansifter"]
}
