variable "environment" {
  description = "Name of the environment, e.g. dev, qa, prod"
}

variable "service_name" {
  description = "Service name, without environment prefix"
}

variable "application_family" {
  description = "Application family to which this service belongs"
  type        = string
}

variable "teams" {
  type        = set(string)
  description = "A set of Datadog Teams to associate the resources with"
  default     = []
}

variable "aws_region" {
  description = "AWS region from which to pull metrics"
  default     = "us-east-1"
}

variable "monitor_enabled" {
  description = "Enable Datadog monitor."
  default     = true
}

variable "evaluation_period" {
  description = "Monitor evaluation period"
  default     = "last_30m"
}

variable "evaluation_delay" {
  description = "Time in seconds to wait for logs to stream in from AWS. Prevents false 'no data'"
  default     = 240
}

variable "critical_number_5XX" {
  description = "Number of 5XX errors needed to trigger an alert"
  default     = 1
}

variable "notification_endpoints" {
  description = "Endpoints for alerts. Can be email, slack, pagerduty, etc"
  default     = null
}

variable "escalation_notification_endpoints" {
  description = "Endpoints for escalation alerts. Can be email, slack, pagerduty, etc"
  default     = null
}

variable "disk_space_monitor_enabled" {
  description = "Enable os_node_disk_space monitor."
  default     = true
}

variable "disk_space_monitor_evaluation_period" {
  description = "Monitor evaluation period"
  default     = "last_5m"
}

variable "disk_space_monitor_evaluation_delay" {
  description = "Time in seconds to wait for logs to stream in from AWS. Prevents false 'no data'"
  default     = 900
}

variable "disk_space_monitor_gib_critical" {
  description = "Minimum GiB of free space needed. You can see this in the AWS console under Minimum free space."
  default     = 15
}

variable "dependent_applications" {
  type        = set(string)
  description = "Optional list of dependent applications to set as a dependent_application tag on resources. These will be combined with programmatically set required tags."
  default     = []
}

locals {
  tags = flatten([
    "application_family:${var.application_family}",
    "env:${var.environment}",
    "environment:${var.environment}",
    "service:${var.service_name}",
    "service_name:${var.service_name}",
    [for team in var.teams : "team:${team}"],
    [for dependent_application in var.dependent_applications : "dependent_application:${dependent_application}"]
  ])

  disk_space_monitor_mib_critical = var.disk_space_monitor_gib_critical * 1024
}
