196 lines
5.3 KiB
HCL
196 lines
5.3 KiB
HCL
variable "libvirt_uri" {
|
||
description = "URI for libvirt connection"
|
||
type = string
|
||
default = "qemu:///system"
|
||
}
|
||
|
||
variable "pool_name" {
|
||
description = "Name of the storage pool"
|
||
type = string
|
||
default = "tf_tmp_pool"
|
||
}
|
||
|
||
variable "pool_path" {
|
||
description = "Path for the storage pool"
|
||
type = string
|
||
default = "/opt/tf_tmp_storage"
|
||
}
|
||
|
||
variable "instance_count" {
|
||
description = "Number of instances to create"
|
||
type = number
|
||
default = 1
|
||
}
|
||
|
||
variable "vm_name" {
|
||
description = "Name prefix for VMs"
|
||
type = string
|
||
}
|
||
|
||
variable "image_location" {
|
||
description = "Location of the OS image"
|
||
type = string
|
||
default = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||
}
|
||
# To avoid refetching the cloud ISO each time, it could could be set to a local directory, like : "/var/lib/libvirt/images/noble-server-cloudimg-amd64.img"
|
||
|
||
variable "cloudinit_filename" {
|
||
description = "Name of the cloud-init ISO file"
|
||
type = string
|
||
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" {
|
||
description = "User data for cloud-init"
|
||
type = string
|
||
default = ""
|
||
}
|
||
|
||
variable "memory" {
|
||
description = "Memory allocation in MB"
|
||
type = number
|
||
default = 2048
|
||
validation {
|
||
condition = var.memory >= 512
|
||
error_message = "Memory must be at least 512MB."
|
||
}
|
||
}
|
||
|
||
variable "vcpu" {
|
||
description = "Number of virtual CPUs"
|
||
type = number
|
||
default = 1
|
||
}
|
||
|
||
variable "network_mode" {
|
||
description = "Network mode (nat, none, route, open, bridge)"
|
||
type = string
|
||
default = "nat"
|
||
}
|
||
|
||
variable "network_domain" {
|
||
description = "Domain name for the network (derived from vm_name)"
|
||
type = string
|
||
# Default dynamically based on vm_name
|
||
default = ""
|
||
}
|
||
|
||
variable "network_addresses" {
|
||
description = "List of network addresses"
|
||
type = list(string)
|
||
default = ["10.17.3.0/24", "2001:db8:ca2:2::1/64"]
|
||
}
|
||
|
||
variable "dns_enabled" {
|
||
description = "Enable DNS for the network"
|
||
type = bool
|
||
default = true
|
||
}
|
||
|
||
variable "dns_local_only" {
|
||
description = "DNS requests only resolved by virtual network's DNS server"
|
||
type = bool
|
||
default = false
|
||
}
|
||
|
||
# Improved UEFI variables with automatic detection
|
||
# For backward compatibility with the current module interface
|
||
variable "uefi_firmware" {
|
||
description = <<EOT
|
||
Enable UEFI support. Set to true to enable UEFI with auto-detected firmware,
|
||
or provide a specific path to the firmware binary.
|
||
Set to false or omit to create a plain BIOS VM.
|
||
EOT
|
||
type = string
|
||
default = ""
|
||
}
|
||
|
||
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 = ""
|
||
}
|
||
|
||
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"
|
||
|
||
# List of common UEFI firmware paths in order of preference
|
||
uefi_firmware_paths = [
|
||
"/usr/share/edk2/ovmf/OVMF_CODE.4m.fd",
|
||
"/usr/share/edk2/x64/OVMF_CODE.4m.fd",
|
||
"/usr/share/OVMF/OVMF_CODE.4m.fd",
|
||
"/usr/share/ovmf/OVMF_CODE.4m.fd",
|
||
"/usr/share/edk2/ovmf/OVMF_CODE.fd",
|
||
"/usr/share/edk2/x64/OVMF_CODE.fd",
|
||
"/usr/share/OVMF/OVMF_CODE.fd",
|
||
"/usr/share/ovmf/OVMF_CODE.fd"
|
||
]
|
||
|
||
uefi_nvram_paths = [
|
||
"/usr/share/edk2/ovmf/OVMF_VARS.4m.fd",
|
||
"/usr/share/edk2/x64/OVMF_VARS.4m.fd",
|
||
"/usr/share/OVMF/OVMF_VARS.4m.fd",
|
||
"/usr/share/ovmf/OVMF_VARS.4m.fd",
|
||
"/usr/share/edk2/ovmf/OVMF_VARS.fd",
|
||
"/usr/share/edk2/x64/OVMF_VARS.fd",
|
||
"/usr/share/OVMF/OVMF_VARS.fd",
|
||
"/usr/share/ovmf/OVMF_VARS.fd"
|
||
]
|
||
|
||
# Determine if UEFI should be enabled
|
||
uefi_enabled = (
|
||
var.uefi_firmware == "true" ||
|
||
var.uefi_firmware == true ||
|
||
(var.uefi_firmware != "" && var.uefi_firmware != false && var.uefi_firmware != null)
|
||
)
|
||
|
||
# Function to get first available firmware path or null
|
||
detected_firmware = (
|
||
local.uefi_enabled ? (
|
||
length(local.uefi_firmware_paths) > 0 ? (
|
||
length([for path in local.uefi_firmware_paths : path if fileexists(path)]) > 0 ?
|
||
[for path in local.uefi_firmware_paths : path if fileexists(path)][0] :
|
||
null
|
||
) : null
|
||
) : null
|
||
)
|
||
|
||
# Function to get first available NVRAM template or null
|
||
detected_nvram = (
|
||
local.uefi_enabled ? (
|
||
length(local.uefi_nvram_paths) > 0 ? (
|
||
length([for path in local.uefi_nvram_paths : path if fileexists(path)]) > 0 ?
|
||
[for path in local.uefi_nvram_paths : path if fileexists(path)][0] :
|
||
null
|
||
) : null
|
||
) : null
|
||
)
|
||
} |