Prasyarat

Panduan

  1. Buat yaml dengan kind: image lalu isikan dengan daftar image yang diinginkan
  • image.yaml
kind: image
uri: "qemu:///system"
spec:
  - name: debian-bullseye
    url: "https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2"
    pool: images
  - name: ubuntu-focal
    url: "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
    pool: images
  1. Buat HCL berdasarkan yaml yang telah dibuat
./tfgen.py -f image.yaml -o image
  • image/main.tf (Hasil tfgen)
terraform {
  required_providers {
    libvirt = {
      source = "dmacvicar/libvirt"
    }
  }
}

provider "libvirt" {
    uri = "qemu:///system"
}

resource "libvirt_volume" "debian-bullseye" {
  name   = "debian-bullseye"
  source = "https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2"
  pool = "images"
}

resource "libvirt_volume" "ubuntu-focal" {
  name   = "ubuntu-focal"
  source = "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
  pool = "images"
}
  1. Berpindah ke direktori yang dihasilkan python-tfgen
cd image/
  1. Jalankan inisiasi terraform
terraform init
  1. Jalankan terraform untuk membuat image
terraform apply

Tips!
Gunakan terraform apply -auto-approve untuk melewati prompt persetujuan.

  1. Verifikasi image yang telah terbuat
virsh vol-list images

Panduan Menghapus

terraform destroy