Compare commits
8 Commits
bfb5f780c8
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
41302119a7 | ||
|
d0dc1f02f6 | ||
|
1f1f2ce12f | ||
|
17a810d9c0 | ||
|
902420a3ea | ||
|
75b2ae6b40 | ||
|
3ae8b81859 | ||
|
3da3aa5cc4 |
@@ -15,7 +15,8 @@ provider "libvirt" {
|
||||
module "shared_modules" {
|
||||
source = "../../shared_modules"
|
||||
|
||||
vm_name = "fedora-cloud-server-42-bios"
|
||||
vm_name = "f42-bios"
|
||||
image_location = "https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2"
|
||||
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMSuVlvOsMqx9qOrKKB1295FjCf2QhHfR1qola9brGkUcFL9dAztG2qdQnpiuPQ4OJpkedrO3C/ixEw1MLTL8l12SvYy/Q9QFguwylp35Nbw1p8h7jrX1FcNLRYltxkMgVhCs1InT5m0lf56bu1h7JfsMs7Ovsy3lU5OdK4h2MysTSKOLctsE4jDJ+XbJYQzj4rbfB/U7/9ple366cGl6xlaHxVfI4BUFWUOiVU4HWvZjrOM5fqPt+AUFRx1l2D7hLUZgOdVQwgO8GFn0sCyCIw0NCXbDn/H05pvWtTUPnyhj5TiseF8qW1byrrT5G8saxwvx8nbIK2tpPfKFdIiL7aj9bYQdltn1knJtvk3hpTPy4QvAbaoGfnfrPAsyU1A/CTw9SD/idvDT2wt1hVsm8EsnpovF7WT5z22fcgoFLDo+QCQrp7t1Wx0/Djay2nThi3FO3N051y5fQWoKOvTsm+rRhrzpDoc+Wtrtss3ua54qnQxHRx3YC0M5Xl9DINkwrcunbZBhozsDG2DzX9qcyzJsSfm9Zt5yM2lpcq+dGPRO1wedw4ogoOpobRr9Cja9W/lJvxmjgIiHz2HbSFPtk/VGjL6M7aQor/GDNN3ugSsfUoTTmNaS9+lWeg+tQWcFUPhYQtQB4/gHQ2u7+mQ0H3hVybsIKIh5XBpAdHQ7pww=="
|
||||
enable_cloudinit = true
|
||||
}
|
27
multiple/environments/phyllome-42-uefi/main.tf
Normal file
27
multiple/environments/phyllome-42-uefi/main.tf
Normal file
@@ -0,0 +1,27 @@
|
||||
terraform {
|
||||
required_version = ">= 0.13"
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.8.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "libvirt" {
|
||||
uri = "qemu:///system"
|
||||
}
|
||||
|
||||
module "shared_modules" {
|
||||
source = "../../shared_modules"
|
||||
|
||||
vm_name = "phyllome-42-uefi"
|
||||
image_location = "/var/lib/libvirt/images/virtual-desktop-hypervisor.img"
|
||||
enable_cloudinit = false
|
||||
# ---- OPTIONAL UEFI SETTINGS ----------------------------------------------
|
||||
uefi_firmware = "/usr/share/edk2/x64/OVMF_CODE.4m.fd"
|
||||
uefi_nvram_template = "/usr/share/edk2/x64/OVMF_VARS.4m.fd"
|
||||
uefi_nvram_file_suffix = "-uefi"
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
}
|
@@ -15,7 +15,8 @@ provider "libvirt" {
|
||||
module "shared_modules" {
|
||||
source = "../../shared_modules"
|
||||
|
||||
vm_name = "ubuntu-cloud-server-2404-bios"
|
||||
vm_name = "u24-bios"
|
||||
image_location = "/var/lib/libvirt/images/noble-server-cloudimg-amd64.img"
|
||||
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMSuVlvOsMqx9qOrKKB1295FjCf2QhHfR1qola9brGkUcFL9dAztG2qdQnpiuPQ4OJpkedrO3C/ixEw1MLTL8l12SvYy/Q9QFguwylp35Nbw1p8h7jrX1FcNLRYltxkMgVhCs1InT5m0lf56bu1h7JfsMs7Ovsy3lU5OdK4h2MysTSKOLctsE4jDJ+XbJYQzj4rbfB/U7/9ple366cGl6xlaHxVfI4BUFWUOiVU4HWvZjrOM5fqPt+AUFRx1l2D7hLUZgOdVQwgO8GFn0sCyCIw0NCXbDn/H05pvWtTUPnyhj5TiseF8qW1byrrT5G8saxwvx8nbIK2tpPfKFdIiL7aj9bYQdltn1knJtvk3hpTPy4QvAbaoGfnfrPAsyU1A/CTw9SD/idvDT2wt1hVsm8EsnpovF7WT5z22fcgoFLDo+QCQrp7t1Wx0/Djay2nThi3FO3N051y5fQWoKOvTsm+rRhrzpDoc+Wtrtss3ua54qnQxHRx3YC0M5Xl9DINkwrcunbZBhozsDG2DzX9qcyzJsSfm9Zt5yM2lpcq+dGPRO1wedw4ogoOpobRr9Cja9W/lJvxmjgIiHz2HbSFPtk/VGjL6M7aQor/GDNN3ugSsfUoTTmNaS9+lWeg+tQWcFUPhYQtQB4/gHQ2u7+mQ0H3hVybsIKIh5XBpAdHQ7pww=="
|
||||
enable_cloudinit = true
|
||||
}
|
28
multiple/environments/ubuntu-cloud-server-2404-uefi/main.tf
Normal file
28
multiple/environments/ubuntu-cloud-server-2404-uefi/main.tf
Normal file
@@ -0,0 +1,28 @@
|
||||
terraform {
|
||||
required_version = ">= 0.13"
|
||||
required_providers {
|
||||
libvirt = {
|
||||
source = "dmacvicar/libvirt"
|
||||
version = "0.8.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "libvirt" {
|
||||
uri = "qemu:///system"
|
||||
}
|
||||
|
||||
module "shared_modules" {
|
||||
source = "../../shared_modules"
|
||||
|
||||
vm_name = "u24-uefi"
|
||||
image_location = "/var/lib/libvirt/images/noble-server-cloudimg-amd64.img"
|
||||
ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMSuVlvOsMqx9qOrKKB1295FjCf2QhHfR1qola9brGkUcFL9dAztG2qdQnpiuPQ4OJpkedrO3C/ixEw1MLTL8l12SvYy/Q9QFguwylp35Nbw1p8h7jrX1FcNLRYltxkMgVhCs1InT5m0lf56bu1h7JfsMs7Ovsy3lU5OdK4h2MysTSKOLctsE4jDJ+XbJYQzj4rbfB/U7/9ple366cGl6xlaHxVfI4BUFWUOiVU4HWvZjrOM5fqPt+AUFRx1l2D7hLUZgOdVQwgO8GFn0sCyCIw0NCXbDn/H05pvWtTUPnyhj5TiseF8qW1byrrT5G8saxwvx8nbIK2tpPfKFdIiL7aj9bYQdltn1knJtvk3hpTPy4QvAbaoGfnfrPAsyU1A/CTw9SD/idvDT2wt1hVsm8EsnpovF7WT5z22fcgoFLDo+QCQrp7t1Wx0/Djay2nThi3FO3N051y5fQWoKOvTsm+rRhrzpDoc+Wtrtss3ua54qnQxHRx3YC0M5Xl9DINkwrcunbZBhozsDG2DzX9qcyzJsSfm9Zt5yM2lpcq+dGPRO1wedw4ogoOpobRr9Cja9W/lJvxmjgIiHz2HbSFPtk/VGjL6M7aQor/GDNN3ugSsfUoTTmNaS9+lWeg+tQWcFUPhYQtQB4/gHQ2u7+mQ0H3hVybsIKIh5XBpAdHQ7pww=="
|
||||
enable_cloudinit = true
|
||||
# ---- OPTIONAL UEFI SETTINGS ----------------------------------------------
|
||||
uefi_firmware = "/usr/share/edk2/x64/OVMF_CODE.4m.fd"
|
||||
uefi_nvram_template = "/usr/share/edk2/x64/OVMF_VARS.4m.fd"
|
||||
uefi_nvram_file_suffix = "-uefi"
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
}
|
@@ -1,8 +1,11 @@
|
||||
# Only create the cloudinit disk if enabled
|
||||
resource "libvirt_cloudinit_disk" "commoninit" {
|
||||
name = var.cloudinit_filename
|
||||
count = var.enable_cloudinit ? var.instance_count : 0
|
||||
|
||||
name = "${var.cloudinit_filename}-${count.index}"
|
||||
user_data = templatefile("${path.module}/cloud_init.yaml", {
|
||||
ssh_key = var.ssh_key
|
||||
})
|
||||
pool = "${var.vm_name}-pool"
|
||||
pool = "${var.vm_name}-pool"
|
||||
depends_on = [libvirt_pool.tf_tmp_storage]
|
||||
}
|
@@ -3,7 +3,40 @@ resource "libvirt_domain" "domain" {
|
||||
name = "${var.vm_name}-${count.index}"
|
||||
memory = var.memory
|
||||
vcpu = var.vcpu
|
||||
cloudinit = libvirt_cloudinit_disk.commoninit.id
|
||||
machine = "q35"
|
||||
|
||||
# The chipset q35, which does not support the IDE bus, does not work with the terraform-provider-libvirt cloud-init implementation,
|
||||
# which creates an ISO attached to an IDE bus by default. Workaround is implemented
|
||||
# https://github.com/dmacvicar/terraform-provider-libvirt/issues/1137#issuecomment-2592329846
|
||||
# A cleaner solution might be the following :
|
||||
# https://github.com/dmacvicar/terraform-provider-libvirt/pull/895#issuecomment-1911167872
|
||||
|
||||
xml {
|
||||
xslt = file("${path.module}/q35-workaround.xslt")
|
||||
}
|
||||
|
||||
# Only include cloudinit if enabled
|
||||
cloudinit = var.enable_cloudinit ? libvirt_cloudinit_disk.commoninit[count.index].id : null
|
||||
|
||||
# ---- optional UEFI support ------------------------------------
|
||||
# Firmware – only add the string when a path is supplied
|
||||
firmware = can(var.uefi_firmware) && length(var.uefi_firmware) > 0 ? var.uefi_firmware : null
|
||||
|
||||
# NVRAM block – dynamic block that is evaluated once per VM
|
||||
dynamic "nvram" {
|
||||
# create the block once if a firmware path *and* a template were given
|
||||
for_each = (can(var.uefi_firmware) && length(var.uefi_firmware) > 0
|
||||
&& can(var.uefi_nvram_template) && length(var.uefi_nvram_template) > 0
|
||||
) ? [1] : []
|
||||
|
||||
content {
|
||||
# The NVRAM filename is per‑VM, but we can honour an optional suffix
|
||||
file = "/var/lib/libvirt/qemu/nvram/${var.vm_name}-${count.index}${var.uefi_nvram_file_suffix}_VARS.fd"
|
||||
template = var.uefi_nvram_template
|
||||
}
|
||||
}
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
cpu {
|
||||
mode = "host-passthrough"
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
resource "libvirt_network" "tf_libvirt_network" {
|
||||
name = "${var.vm_name}-network"
|
||||
mode = var.network_mode
|
||||
domain = var.network_domain
|
||||
domain = local.computed_network_domain
|
||||
addresses = var.network_addresses
|
||||
|
||||
dns {
|
||||
|
16
multiple/shared_modules/q35-workaround.xslt
Normal file
16
multiple/shared_modules/q35-workaround.xslt
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" ?>
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output omit-xml-declaration="yes" indent="yes"/>
|
||||
<xsl:template match="node()|@*">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="node()|@*"/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
<xsl:template match="/domain/devices/disk[@device='cdrom']/target/@bus">
|
||||
<xsl:attribute name="bus">
|
||||
<xsl:value-of select="'sata'"/>
|
||||
</xsl:attribute>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="/domain/devices/disk[@device='cdrom']/alias" />
|
||||
</xsl:stylesheet>
|
@@ -40,9 +40,16 @@ variable "cloudinit_filename" {
|
||||
default = "commoninit.iso"
|
||||
}
|
||||
|
||||
variable "enable_cloudinit" {
|
||||
description = "Enable cloud-init support"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "ssh_key" {
|
||||
description = "SSH authorized keys for cloud-init"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "user_data" {
|
||||
@@ -64,13 +71,7 @@ variable "memory" {
|
||||
variable "vcpu" {
|
||||
description = "Number of virtual CPUs"
|
||||
type = number
|
||||
default = 1
|
||||
}
|
||||
|
||||
variable "network_name" {
|
||||
description = "Name of the network"
|
||||
type = string
|
||||
default = "tf"
|
||||
default = 2
|
||||
}
|
||||
|
||||
variable "network_mode" {
|
||||
@@ -80,9 +81,10 @@ variable "network_mode" {
|
||||
}
|
||||
|
||||
variable "network_domain" {
|
||||
description = "Domain name for the network"
|
||||
description = "Domain name for the network (derived from vm_name)"
|
||||
type = string
|
||||
default = "tf.local"
|
||||
# Default dynamically based on vm_name
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "network_addresses" {
|
||||
@@ -101,4 +103,39 @@ variable "dns_local_only" {
|
||||
description = "DNS requests only resolved by virtual network's DNS server"
|
||||
type = bool
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "uefi_firmware" {
|
||||
description = <<EOT
|
||||
Path to the UEFI firmware binary (OVMF_CODE.fd, QEMU_CODE.fd, …).
|
||||
Leave empty (or omit on the module call) to create a plain BIOS VM.
|
||||
EOT
|
||||
type = string
|
||||
default = "" # “BIOS only” when empty
|
||||
}
|
||||
|
||||
variable "uefi_nvram_template" {
|
||||
description = <<EOT
|
||||
Path to an NV‑RAM template that backs the UEFI NVRAM.
|
||||
If you specify a template, the VM will get a writable NVRAM block.
|
||||
Leave empty for a plain BIOS VM or if you don’t need UEFI NVRAM.
|
||||
EOT
|
||||
type = string
|
||||
default = "" # no NVRAM when empty
|
||||
}
|
||||
|
||||
variable "uefi_nvram_file_suffix" {
|
||||
description = <<EOT
|
||||
Optional file‑suffix fragment that is appended to the
|
||||
generated NVRAM file name. Useful when you want to put the
|
||||
files under a dedicated directory (`/var/lib/libvirt/qemu/uefi/nvram/…`).
|
||||
Empty string means “no suffix” (default behaviour).
|
||||
EOT
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
# Computed variable for network domain (derived from vm_name)
|
||||
locals {
|
||||
computed_network_domain = var.network_domain != "" ? var.network_domain : "${var.vm_name}.local"
|
||||
}
|
Reference in New Issue
Block a user