# Download Debian 12 LXC template to gihyeon2
resource "proxmox_virtual_environment_download_file" "debian12_template" {
  content_type = "vztmpl"
  datastore_id = "local"
  node_name    = "gihyeon2"
  url          = "http://download.proxmox.com/images/system/debian-12-standard_12.12-1_amd64.tar.zst"
}

# PBS LXC Container on gihyeon2
resource "proxmox_virtual_environment_container" "pbs" {
  description   = "Proxmox Backup Server - Managed by Terraform"
  node_name     = "gihyeon2"
  vm_id         = 200
  start_on_boot = true
  unprivileged  = true
  tags          = ["infra", "backup", "terraform"]

  operating_system {
    template_file_id = proxmox_virtual_environment_download_file.debian12_template.id
    type             = "debian"
  }

  cpu {
    cores = 1
  }

  memory {
    dedicated = 2048
    swap      = 512
  }

  disk {
    datastore_id = "local-lvm"
    size         = 16
  }

  # SDN network interface
  network_interface {
    name   = "eth0"
    bridge = var.pbs_network_bridge
  }

  initialization {
    hostname = "pbs"

    ip_config {
      ipv4 {
        address = var.pbs_ip_address
        gateway = var.pbs_gateway
      }
    }

    dns {
      servers = var.dns_servers
    }
  }
}
