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

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

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

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

variable "team_name" {
  default = "accounting"
}

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

locals {
  state_machine_definition = jsonencode({
    Comment = "Run QA task and finish",
    StartAt = "WaitFiveMinutes",
    States : {
      WaitFiveMinutes : {
        Type     = "Wait",
        Seconds  = 300,
        Next     = "RunQA"
      },
      RunQA : {
        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 = "$.qaTaskResult",
        End        = true
      }
    }
  })
}
