terraform {
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
      version = "0.7.6"
    }
  }
}

provider "libvirt" {
  uri = "qemu+ssh://root@betelgeuse-seven-unraid/system?&known_hosts_verify=ignore"
}

resource "libvirt_pool" "terraform" {
  name = "terraform"
  type = "dir"
  path = "/mnt/user/domains/terraform"
}

# resource "libvirt_ignition" "ignition" {
#   name = "example.ign"
#   content = "../1-prepare-ignition-files/jaglan-beta-m40.ign"
# }

resource "libvirt_volume" "fedora-coreos-39" {
  name = "fedora-coreos-39.20231119.3.0-qemu.qcow2"
  pool = libvirt_pool.terraform.name
  source = "https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/39.20231119.3.0/x86_64/fedora-coreos-39.20231119.3.0-qemu.x86_64.qcow2.xz"
}

resource "libvirt_volume" "default" {
  name = "test.qcow2"
  pool = libvirt_pool.terraform.name
  size = 10737418240 #10G
  base_volume_id = libvirt_volume.fedora-coreos-39.id
}

resource "libvirt_domain" "default" {
  name = "test"
  description = "v0.3"
  vcpu = 1
  memory = 1024
  #coreos_ignition = libvirt_ignition.ignition.id
  disk {
    volume_id = libvirt_volume.default.id
  }
#   disk {
#     file = "/mnt/user/isos/fedora-coreos-39.20231119.3.0-qemu.x86_64.qcow2"
#   }
#   boot_device {
#     dev = [ "hd"
#     #, "cdrom"
#     ]
#   }
}