I am trying to build test servers using Terraform on KVM. It works if I use:
source = “https://download.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-LVM.latest.x86_64.qcow2”
But hangs if I change this to R9 or R10 images?
The other issue I have is if I try to create a fixed-IP it is ignored and I still get a DHCP address?
data "template_file" "network_config" {
template = file("${path.module}/network.cfg")
}
# cat network.cfg
# Source - https://stackoverflow.com/q
# Posted by Lion, modified by community. See post 'Timeline' for change history
# Retrieved 2025-12-12, License - CC BY-SA 4.0
version: 2
ethernets:
ens3:
dhcp4: false
dhcp6: false
addresses:
- 10.21.184.199
gateway4: 10.21.184.1
I also tried via the cloud_init.cfg:
cat cloud_init.cfg
#cloud-config
..
network:
version: 2
ethernets:
ens3:
dhcp4: no
addresses:
- 10.21.184.199/22
gateway4: 10.21.184.1
nameservers:
addresses:
- 10.21.184.1
Does anyone know why Terraform doesn’t work with Rocky9 and 10, and has anyone managed to create a VM with a fixed-IP?
I have created a main.tf that works for Rocky-10 but not 9?
cat main.tf
resource “libvirt_volume” “qcow_volume” {
name = “${var.vm_name}.qcow2”
pool = “default”
#source = “https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-LVM.latest.x86_64.qcow2”
source = “https://download.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-LVM.latest.x86_64.qcow2”
format = “qcow2”
}
data “template_file” “user_data” {
template = file(“${path.module}/cloud_init.cfg”)
vars = {
hostname = var.host_name
domain = var.domain
}
}
data “template_file” “network_config” {
template = file(“${path.module}/network.cfg”)
}
resource “libvirt_cloudinit_disk” “commoninit” {
name = “commoninit.iso”
pool = “default”
user_data = data.template_file.user_data.rendered
network_config = data.template_file.network_config.rendered
}
Define KVM domain to create
resource “libvirt_domain” “default” {
name = var.vm_name
memory = var.memory
vcpu = var.cpu
qemu_agent = true
cloudinit = libvirt_cloudinit_disk.commoninit.id
#machine = “q35”
cpu {
mode = “host-passthrough”
}
disk {
volume_id = libvirt_volume.qcow_volume.id
}
console {
type = “pty”
target_type = “serial”
target_port = “0”
}
graphics {
type = “vnc”
listen_type = “address”
autoport = true
}
network_interface {
network_name = “default”
addresses = [var.ip_address]
hostname = “${var.host_name}.${var.domain}”
wait_for_lease = false
}
connection {
type = “ssh”
user = var.ssh_username
host = libvirt_domain.domain-.var.vm_name.network_interface[0].addresses[0]
private_key = file(var.ssh_private_key)
timeout = “2m”
}
}
The biggest problem is creating a cloud_init.cfg and network.cfg as Rocky8, 9, and 10 all treat them differently.
Any ideas how I can get this working for Rocky-9 as 8 is too old and 10 is a bit unstable at present.
network.cfg:
cat network.cfg
Source - https://stackoverflow.com/q
Posted by Lion, modified by community. See post ‘Timeline’ for change history
Retrieved 2025-12-12, License - CC BY-SA 4.0
version: 2
ethernets:
eth0:
match:
macaddress: “52:54:00:1a:d3:57”
set-name: eth0
addresses:
- 10.21.1.199/22
gateway4: 10.21.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
dhcp4: false
dhcp6: false