module "db" {
  source = "./modules/db"

  target_node     = "px"
  vm_hostname     = "db"
  ostemplate      = "local:vztmpl/ubuntu-22.04-custome.tar.zst"
  ssh_public_key  = file("./ssh/id_terraform.pub")
  private_key     = file("./ssh/id_terraform")
  ip_address      = "10.10.10.3"
  gateway         = "10.10.10.1"
  bridge          = "vmbr1"
  storage         = "local"
  size            = "8G"

  lxc_resources = {
    cores  = 2
    memory = 2048
    swap   = 512
  }

}

module "app" {
  source = "./modules/app"

  target_node     = "px"
  vm_hostname     = "app-01"
  ostemplate      = "local:vztmpl/ubuntu-22.04-custome.tar.zst"
  ssh_public_key  = file("./ssh/id_terraform.pub")
  private_key     = file("./ssh/id_terraform")
  db_host = module.db.db_ip
  ip_address      = "10.10.10.4"
  gateway         = "10.10.10.1"
  bridge          = "vmbr1"
  storage         = "local"
  size            = "8G"

  lxc_resources = {
    cores  = 2
    memory = 2048
    swap   = 512
  }

}

locals {
  modules_enabled = var.enable_monitoring ? toset(["monitoring"]) : []
}

module "monitoring" {
  for_each = local.modules_enabled
  source   = "./modules/monitoring"

  target_node     = "px"
  vm_hostname     = "prometheus"
  ostemplate      = "local:vztmpl/ubuntu-22.04-custome.tar.zst"
  ssh_public_key  = file("./ssh/id_terraform.pub")
  private_key     = file("./ssh/id_terraform")
  ip_address      = "10.10.10.10"
  gateway         = "10.10.10.1"
  bridge          = "vmbr1"
  storage         = "local"
  size            = "8G"

  lxc_resources = {
    cores  = 2
    memory = 2048
    swap   = 512
  }
}
