module "fargate_service_dashboard" {
  source                            = "git@github.com:theorchard/terraform-datadog.git//modules/service?ref=6.15.2"
  environment                       = var.environment
  environment_type                  = "fargate"
  service_name                      = var.service_name
  service_4xx_monitor_enabled       = false
  service_5xx_monitor_enabled       = false
  service_cpu_monitor_silenced      = true
  healthy_tasks_monitor_silenced    = true
  notification_endpoints            = var.notification_endpoints
  escalation_notification_endpoints = var.notification_endpoints
  application_family                = var.application_family
}

resource "datadog_monitor" "backup_monitor" {
  name               = "Route53 Backups Monitor"
  type               = "metric alert"
  message            = "Route53 backups have not run successfully for account {{account_id.name}}. Notify: ${var.notification_endpoints}"
  escalation_message = "Route53 backups have still not run successfully for account {{account_id.name}}. Escalation to ${var.notification_endpoints}"

  query = "sum(last_25h):sum:route53_backup.success{*} by {account_id} < 1"

  monitor_thresholds {
    critical = 1
  }

  notify_no_data      = true
  renotify_interval   = 60 * 24
  require_full_window = false
  no_data_timeframe   = 0

  tags = [
    "environment:${var.environment}",
    "service_name:${var.service_name}",
    "application_family:${var.application_family}"
  ]
}
