2023-11-25 20:00:21 +00:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
libvirt = {
|
|
|
|
source = "dmacvicar/libvirt"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_volume" "os" {
|
|
|
|
name = "${var.name}.qcow2"
|
|
|
|
pool = "disks"
|
|
|
|
size = 1024 * 1024 * 1024 * var.storage
|
|
|
|
base_volume_name = "debian-bookworm.qcow2"
|
|
|
|
base_volume_pool = "images"
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
replace_triggered_by = [
|
|
|
|
libvirt_cloudinit_disk.main.id
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_cloudinit_disk" "main" {
|
|
|
|
name = "${var.name}.iso"
|
|
|
|
pool = "cloudinit"
|
|
|
|
user_data = templatefile("${path.module}/files/cloud_init.cfg.tftpl", {
|
|
|
|
hostname = var.name
|
2023-12-25 18:22:22 +00:00
|
|
|
data_disk = var.data_disk
|
2023-11-25 20:00:21 +00:00
|
|
|
})
|
2023-12-17 15:22:22 +00:00
|
|
|
network_config = templatefile("${path.module}/files/network_config.cfg.tftpl", {
|
|
|
|
static_ip = var.static_ip
|
|
|
|
})
|
2023-11-25 20:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "libvirt_domain" "main" {
|
|
|
|
name = var.name
|
|
|
|
memory = var.ram
|
|
|
|
vcpu = 4
|
|
|
|
autostart = true
|
|
|
|
|
|
|
|
disk {
|
|
|
|
volume_id = libvirt_volume.os.id
|
|
|
|
}
|
|
|
|
|
2023-12-25 18:22:22 +00:00
|
|
|
dynamic "disk" {
|
|
|
|
for_each = var.data_disk != null ? [1] : []
|
|
|
|
|
|
|
|
content {
|
|
|
|
volume_id = var.data_disk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-25 20:00:21 +00:00
|
|
|
network_interface {
|
|
|
|
bridge = "bridgedmz"
|
|
|
|
hostname = var.name
|
2023-11-29 17:59:36 +00:00
|
|
|
mac = var.mac
|
2023-11-25 20:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cloudinit = libvirt_cloudinit_disk.main.id
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
replace_triggered_by = [
|
|
|
|
libvirt_cloudinit_disk.main.id
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|