variable "aws_region" {
  default     = "us-east-1"
  description = "AWS region"
}

variable "environment" {
  description = "Available values:  dev, qa, prod."
  default     = "prod"
}

variable "service_name" {
  default = "dbt-accounting"
}

variable "application_family" {
  description = "Application family"
  default     = "accounting"
}

variable "secrets_manager_secret_names" {
  description = "List of secrets manager secrets to create"
  type        = list(string)
  default = [
    "SNOWFLAKE_PRIVATE_KEY",
  ]
}

variable "team_name" {
  default = "accounting"
}

variable "notification_escalation_endpoint" {
  description = "DataDog notification endpoints"
  default     = "@slack-moneyhub"
}

variable "notification_alerts_endpoint" {
  description = "DataDog notification endpoints"
  default     = "@slack-moneyhub-alerts"
}

locals {
  state_machine_definition = jsonencode({
    Comment = "Run Prod dbt Accounting Task",
    StartAt = "RunProd",
    States : {
      RunProd : {
        Type : "Task",
        Resource : "arn:aws:states:::ecs:runTask.sync",
        Parameters : {
          Cluster        = module.dbt_accounting_fargate_environment.fargate_cluster_arn,
          TaskDefinition = module.dbt_accounting_fargate_environment.fargate_task_definition_arn_without_revision,
          LaunchType     = "FARGATE",
          NetworkConfiguration : {
            AwsvpcConfiguration : {
              Subnets = module.vpc_info.default_private_subnet_ids,
              SecurityGroups = [
                module.dbt_accounting_fargate_environment.fargate_security_group_id,
              ]
              AssignPublicIp = "DISABLED"
            }
          },
          Overrides : {
            ContainerOverrides : [
              {
                Name = "dbt-accounting",
                Environment : [
                  { Name : "DBT_SELECT_MODELS", "Value.$" : "$.DBT_SELECT_MODELS" },
                  { Name : "DBT_EXCLUDE_MODELS", "Value.$" : "$.DBT_EXCLUDE_MODELS" },
                  { Name : "DBT_FULL_REFRESH", "Value.$" : "$.DBT_FULL_REFRESH" },
                ]
              }
            ]
          },
        },
        ResultPath : "$.prodTaskResult",
        End : true
      }
    }
  })
}
