variable "project_group" {
  type        = string
  description = "The name of the project group."
}

variable "env_prefix" {
  type        = string
  description = "The short name of the environment."
}

/**
 * Toggle
 */
variable "datadog_enabled" {
  type        = bool
  description = "Specify whether you want the datadog container or not."
  default     = false
}

variable "awslogs_create_group" {
  type        = bool
  description = "Specify whether create log group or not."
  default     = true
}

variable "efs_volume_enabled" {
  type        = bool
  description = "Specify whether you want to use EFS volume or not."
  default     = false
}

/**
 * Datadog configuration
 */
variable "dd_container_image" {
  type        = string
  description = "The image used to start the container with Datadog agent."
  default     = "public.ecr.aws/datadog/agent:latest"
}

variable "dd_container_name" {
  type        = string
  description = "The name of the container."
  default     = "datadog-agent"
}

variable "dd_logs_injection" {
  type        = bool
  description = "Specify whether you want to use Datadog logs injection or not."
  default     = false
}

variable "dd_apm_enabled" {
  type        = bool
  description = "Specify whether you want to use Datadog APM or not."
  default     = false
}

variable "dd_profiling_enabled" {
  type        = bool
  description = "Specify whether you want to use Datadog Profiling or not"
  default     = false
}

variable "dd_service" {
  type        = string
  description = "Datadog service name. Set byt default to {project_group}-{container_name}"
  default     = ""
}

variable "dd_env" {
  type        = string
  description = "Datadog env. Set byt default to variable env_prefix"
  default     = ""
}

variable "dd_env_vars" {
  type = list(object({
    name  = string
    value = string
  }))
  description = "The environment variables to pass to the container with Datadog agent. This is a list of maps. map_environment overrides environment."
  default     = []
}
variable "dd_port_mappings" {
  type = list(object({
    containerPort = number
    hostPort      = number
    protocol      = string
  }))
  description = "The port mappings to configure for the container. This is a list of maps. Each map should contain \"containerPort\", \"hostPort\", and \"protocol\", where \"protocol\" is one of \"tcp\" or \"udp\". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort"
  default     = []
}


variable "dd_secrets" {
  type = list(object({
    name      = string
    valueFrom = string
  }))
  description = "The secrets to pass to the container with Datadog agent. This is a list of maps."
  default     = null
}


variable "dd_awslogs_group" {
  type        = string
  description = "The name of the log group where awslogs driver will send events from container with Datadog."
  default     = null
}

variable "dd_docker_labels" {
  type    = map(string)
  default = {}
}

/**
 * Container definition
 */
variable "container_name" {
  type        = string
  description = "The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed)."
}

variable "container_image" {
  type        = string
  description = "The image used to start the container. Images in the Docker Hub registry available by default."
}

variable "env_vars" {
  type = list(object({
    name  = string
    value = string
  }))
  description = "The environment variables to pass to the container. This is a list of maps. map_environment overrides environment."
  default     = []
}

variable "port_mappings" {
  type = list(object({
    containerPort = number
    hostPort      = number
    protocol      = string
  }))
  description = "The port mappings to configure for the container. This is a list of maps. Each map should contain \"containerPort\", \"hostPort\", and \"protocol\", where \"protocol\" is one of \"tcp\" or \"udp\". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort"
  default     = []
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html
variable "healthcheck" {
  type = object({
    command     = list(string)
    retries     = number
    timeout     = number
    interval    = number
    startPeriod = number
  })
  description = "A map containing command (string), timeout, interval (duration in seconds), retries (1-10, number of times to retry before marking container unhealthy), and startPeriod (0-300, optional grace period to wait, in seconds, before failed healthchecks count toward retries)."
  default     = null
}

variable "secrets" {
  type = list(object({
    name      = string
    valueFrom = string
  }))
  description = "The secrets to pass to the container. This is a list of maps."
  default     = null
}

variable "command" {
  type        = list(string)
  description = "The command that is passed to the container."
  default     = null
}

variable "entrypoint" {
  type        = list(string)
  description = "The entrypoint that is passed to the container."
  default     = null
}

variable "working_directory" {
  type        = string
  description = "The working directory to run commands inside the container."
  default     = null
}

variable "ulimits" {
  type = list(object({
    name      = string
    hardLimit = number
    softLimit = number
  }))
  description = "Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\"."
  default     = null
}

variable "mount_points" {
  type = list(object({
    containerPath = string
    sourceVolume  = string
    readOnly      = bool
  }))

  description = "Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional."
  default     = []
}

variable "volumes_from" {
  type = list(object({
    sourceContainer = string
    readOnly        = bool
  }))

  description = "A list of VolumesFrom maps which contain \"sourceContainer\" (name of the container that has the volumes to mount) and \"readOnly\" (whether the container can write to the volume)"
  default     = []
}

variable "system_controls" {
  type        = list(map(string))
  description = "A list of namespaced kernel parameters to set in the container, mapping to the --sysctl option to docker run. This is a list of maps: { namespace = \"\", value = \"\"}"
  default     = null
}

// Logs configuration
variable "awslogs_group_name" {
  type        = string
  description = "The name of the log group where awslogs driver will send events."
  default     = ""
}

variable "awslogs_region" {
  type        = string
  description = "The region to which the awslogs log driver should send your Docker logs. "
  default     = "us-east-1"
}

variable "awslogs_stream_prefix" {
  type        = string
  description = "The stream-prefix for your logs."
  default     = "ecs"
}

variable "awslogs_retention" {
  type        = number
  description = "Logs will expire after this period of time"
  default     = 0
}

/**
 * Task configuration
 */
variable "family" {
  type        = string
  description = "(Required) A unique name for your task definition."
}

variable "task_role_arn" {
  type        = string
  description = "(Optional) The ARN of IAM role that allows your Amazon ECS container task to make calls to other AWS services."
}

variable "exec_role_arn" {
  type        = string
  description = "(Optional) The Amazon Resource Name (ARN) of the task execution role that the Amazon ECS container agent and the Docker daemon can assume."
}

variable "cpu" {
  type        = number
  description = "The number of cpu units used by the task."
}

variable "memory" {
  type        = number
  description = "The amount (in MiB) of memory used by the task."
}

/**
 * EFS configuration
 */
variable "efs_volume_name" {
  type        = string
  description = "The name of the volume."
  default     = null
}

variable "efs_file_system_id" {
  type        = string
  description = "The ID of the EFS File System."
  default     = null
}

variable "efs_root_directory" {
  type        = string
  description = "The directory within the Amazon EFS file system to mount as the root directory inside the host."
  default     = null
}

variable "common_tags" {
  type        = map(string)
  description = "Key-value map of resource tags."
  default     = {}
}

variable "docker_labels" {
  type        = map(string)
  description = "Key-value map of docker labels."
  default     = null
}

variable "defender_enabled" {
  type        = bool
  description = "Enable Cloud Prisma embedded defender"
  default     = false
}

variable "defender_secrets" {
  type = list(object({
    name      = string
    valueFrom = string
  }))
  description = "The secrets to pass to the container. This is a list of maps."
  default     = null
}

variable "stop_timeout" {
  type        = number
  description = "Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own"
  default     = null
}

variable "user" {
  type        = string
  description = "The user to use inside the container."
  default     = null
}

variable "init_process_enabled" {
  type    = bool
  default = null
}

variable "ephemeral_storage_size" {
  type        = number
  description = "The amount of ephemeral storage to allocate for the task. This parameter is used to expand the total amount of ephemeral storage available, beyond the default amount, for tasks hosted on AWS Fargate."
  default     = 20
}
