module "stripo_plugin_statistics_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}-statistics-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                        = "/actuator/health/liveness"
  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/stripo-plugin-details-service:1.175.0"
  custom_waf_arn                           = module.stripo_waf.waf_blocking_arn_output
  https_listener_certificate_id            = var.https_listener_certificate_id

  environment_variables = [
    {
      Environment = var.environment
    },
    {
      DD_TRACE_ANALYTICS_ENABLED = "true"
    },
    {
      DD_TRACE_APP_NAME = "${var.environment}-${var.service_name}"
    },
    {
      APPNAME = "statistics-service"
    },
    {
      ENV = "PLUGINS"
    },
    {
      PROFILE = "PLUGINS"
    },
    {
      SPRING_CONFIG_NAME = "application,jdbc,log,base"
    },
    {
      SPRING_CLOUD_CONFIG_ENABLED = "false"
    },
    {
      JVM_MEMORY_OPTS = "-Dspring.cloud.config.enabled=false -Daws.secretsmanager.enabled=false"
    },
    {
      JAVA_TOOL_OPTIONS = "-Xss256k -Xms256m -Xmx400m -XX:ReservedCodeCacheSize=128M"
    },
    {
      SPRING_DATASOURCE_URL = "jdbc:postgresql://${module.stripo_postgres_rds.aws_route53_record_rds_cluster_cname}:5432/stripo_plugin_local_plugin_stats"
    },
    {
      SPRING_DATASOURCE_USERNAME = "stripo"
    },
    {
      LOGGING_LEVEL_ROOT = "INFO"
    },
    {
      SPRING_ZIPKIN_ENABLED = "false"
    },
    {
      MANAGEMENT_TRACING_SAMPLING_PROBABILITY = "0"
    },
    {
      MANAGEMENT_SERVER_PORT = "8080"
    },
    {
      MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE = "health,prometheus,metrics"
    },
    {
      MANAGEMENT_ENDPOINT_HEALTH_PROBES_ENABLED = "true"
    },
    {
      MANAGEMENT_ADDRESS = "0.0.0.0"
    },
    {
      MANAGEMENT_SECURITY_ENABLED = "false"
    }
  ]
  secrets = [
    {
      SPRING_DATASOURCE_PASSWORD = "${var.environment}/${var.service_name}-statistics-service/RDS_DB_PASSWORD"
    }
  ]
}

module "statistics_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}-statistics-service"
  application_family                = var.application_family
  notification_endpoints            = var.application_alert_channel
  escalation_notification_endpoints = var.application_alert_channel
  teams                             = ["fansifter"]
}
