homelab-server-v2/terraform/main.tf
2026-07-14 04:14:01 +00:00

234 lines
5.9 KiB
HCL

terraform {
required_version = ">= 1.5.0"
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "0.7.6"
}
}
}
provider "libvirt" {
uri = "qemu+ssh://sho@172.30.1.200/system"
}
resource "libvirt_pool" "vm_storage_pool" {
name = "vm_pool"
type = "dir"
path = "/var/lib/libvirt/images/vm_pool"
}
resource "libvirt_volume" "almalinux10_image" {
name = "almalinux10-base.qcow2"
pool = libvirt_pool.vm_storage_pool.name
source = "https://repo.almalinux.org/almalinux/10/cloud/x86_64/images/AlmaLinux-10-GenericCloud-latest.x86_64.qcow2"
format = "qcow2"
}
resource "libvirt_volume" "debian12_image" {
name = "debian12-base.qcow2"
pool = libvirt_pool.vm_storage_pool.name
source = "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2"
format = "qcow2"
}
resource "libvirt_volume" "ubuntu2404_image" {
name = "ubuntu2404-base.qcow2"
pool = libvirt_pool.vm_storage_pool.name
source = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
format = "qcow2"
}
resource "libvirt_volume" "freeipa_disk" {
name = "freeipa-disk.qcow2"
pool = libvirt_pool.vm_storage_pool.name
base_volume_id = libvirt_volume.almalinux10_image.id
size = 42949672960
format = "qcow2"
}
resource "libvirt_volume" "portfolio_disk" {
name = "portfolio-disk.qcow2"
pool = libvirt_pool.vm_storage_pool.name
base_volume_id = libvirt_volume.debian12_image.id
size = 10737418240
format = "qcow2"
}
resource "libvirt_volume" "minecraft_disk" {
name = "minecraft-disk.qcow2"
pool = libvirt_pool.vm_storage_pool.name
base_volume_id = libvirt_volume.debian12_image.id
size = 21474836480
format = "qcow2"
}
resource "libvirt_volume" "palworld_disk" {
name = "palworld-disk.qcow2"
pool = libvirt_pool.vm_storage_pool.name
base_volume_id = libvirt_volume.ubuntu2404_image.id
size = 32212254720
format = "qcow2"
}
resource "libvirt_volume" "navidrome_disk" {
name = "navidrome-disk.qcow2"
pool = libvirt_pool.vm_storage_pool.name
base_volume_id = libvirt_volume.debian12_image.id
size = 16106127360
format = "qcow2"
}
data "template_file" "user_data" {
template = file("${path.module}/templates/cloud_init.cfg")
vars = {
admin_user = "sho"
ssh_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILM/84tpkx+yYsA8Zr5or1xuELOGMl0JEP576SyUc9eC sho@bazzite"
}
}
resource "libvirt_cloudinit_disk" "freeipa_init" {
name = "freeipa-init.iso"
pool = libvirt_pool.vm_storage_pool.name
user_data = data.template_file.user_data.rendered
}
resource "libvirt_cloudinit_disk" "portfolio_init" {
name = "portfolio-init.iso"
pool = libvirt_pool.vm_storage_pool.name
user_data = data.template_file.user_data.rendered
}
resource "libvirt_cloudinit_disk" "minecraft_init" {
name = "minecraft-init.iso"
pool = libvirt_pool.vm_storage_pool.name
user_data = data.template_file.user_data.rendered
}
resource "libvirt_cloudinit_disk" "palworld_init" {
name = "palworld-init.iso"
pool = libvirt_pool.vm_storage_pool.name
user_data = data.template_file.user_data.rendered
}
resource "libvirt_cloudinit_disk" "navidrome_init" {
name = "navidrome-init.iso"
pool = libvirt_pool.vm_storage_pool.name
user_data = data.template_file.user_data.rendered
}
resource "libvirt_domain" "freeipa_vm" {
name = "freeipa"
memory = "3072"
vcpu = 2
cpu { mode = "host-passthrough" }
cloudinit = libvirt_cloudinit_disk.freeipa_init.id
network_interface {
bridge = "br0"
mac = "52:54:00:ee:ef:61"
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
disk { volume_id = libvirt_volume.freeipa_disk.id }
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
resource "libvirt_domain" "portfolio_vm" {
name = "portfolio"
memory = "1024"
vcpu = 1
cpu { mode = "host-passthrough" }
cloudinit = libvirt_cloudinit_disk.portfolio_init.id
network_interface {
bridge = "br0"
mac = "52:54:00:ee:ef:62"
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
disk { volume_id = libvirt_volume.portfolio_disk.id }
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
resource "libvirt_domain" "minecraft_vm" {
name = "minecraft"
memory = "6144"
vcpu = 2
cpu { mode = "host-passthrough" }
cloudinit = libvirt_cloudinit_disk.minecraft_init.id
network_interface {
bridge = "br0"
mac = "52:54:00:ee:ef:63"
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
disk { volume_id = libvirt_volume.minecraft_disk.id }
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
resource "libvirt_domain" "palworld_vm" {
name = "palworld"
memory = "12288"
vcpu = 4
cpu { mode = "host-passthrough" }
cloudinit = libvirt_cloudinit_disk.palworld_init.id
network_interface {
bridge = "br0"
mac = "52:54:00:ee:ef:64"
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
disk { volume_id = libvirt_volume.palworld_disk.id }
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
resource "libvirt_domain" "navidrome_vm" {
name = "navidrome"
memory = "1024"
vcpu = 1
cpu { mode = "host-passthrough" }
cloudinit = libvirt_cloudinit_disk.navidrome_init.id
network_interface {
bridge = "br0"
mac = "52:54:00:ee:ef:65"
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
disk { volume_id = libvirt_volume.navidrome_disk.id }
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}