Prasyarat
- Terraform
- python-tfgen
- Storage Pool (Baca disini untuk cara membuat Storage Pool)
Panduan
- 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
- 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"
}
- Berpindah ke direktori yang dihasilkan python-tfgen
cd image/
- Jalankan inisiasi terraform
terraform init
- Jalankan terraform untuk membuat image
terraform apply
Tips!
Gunakanterraform apply -auto-approve
untuk melewati prompt persetujuan.
- Verifikasi image yang telah terbuat
virsh vol-list images
Panduan Menghapus
terraform destroy