variable "wait_on" {
  type        = any
  description = "Resources to wait on"
  default     = true
}

variable "server_ip" {
  type = string
}

variable "ssh_private_key_path" {
  type = string
}

variable "server_domain" {}

resource "random_password" "api_key" {
  length  = 64
  special = false
}

module "qdrant" {
  source = "../quadlet-app"
  wait_on = var.wait_on

  server_ip            = var.server_ip
  ssh_private_key_path = var.ssh_private_key_path

  app_name = "qdrant"
  image    = "docker.io/qdrant/qdrant"
  ports    = ["6333:6333", "6334:6334"]
  volumes  = ["/opt/storage/data/qdrant:/qdrant/storage:z"]

  environment = {
    "QDRANT__SERVICE__API_KEY" = random_password.api_key.result
  }

  haproxy_services = [
    {
      name   = "qdrant"
      domain = "qdrant.${var.server_domain}"
      port   = "6333"
      host   = "127.0.0.1"
      tls    = false
      #grpc_port = "6334"
    },
  ]

}

output "app_urls" {
  value = module.qdrant.app_urls
}

output "installed" {
  value = true
  depends_on = [module.qdrant.installed]
}

output "api_key" {
  value = random_password.api_key.result
  sensitive = true
}