Simplify the logic so that when uefi_firmware is not set to true (or the line does not appear in main.tf), will default to BIOS

This commit is contained in:
Lukas Greve
2025-10-20 20:27:35 +02:00
parent 87dc196f77
commit ca2e84496a

View File

@@ -106,6 +106,7 @@ variable "dns_local_only" {
} }
# Improved UEFI variables with automatic detection # Improved UEFI variables with automatic detection
# For backward compatibility with the current module interface
variable "uefi_firmware" { variable "uefi_firmware" {
description = <<EOT description = <<EOT
Enable UEFI support. Set to true to enable UEFI with auto-detected firmware, Enable UEFI support. Set to true to enable UEFI with auto-detected firmware,
@@ -137,7 +138,6 @@ variable "uefi_nvram_file_suffix" {
default = "" default = ""
} }
# Computed variable for network domain (derived from vm_name) # Computed variable for network domain (derived from vm_name)
locals { locals {
computed_network_domain = var.network_domain != "" ? var.network_domain : "${var.vm_name}.local" computed_network_domain = var.network_domain != "" ? var.network_domain : "${var.vm_name}.local"
@@ -165,43 +165,32 @@ locals {
"/usr/share/ovmf/OVMF_VARS.fd" "/usr/share/ovmf/OVMF_VARS.fd"
] ]
# Helper function to find first existing file # Determine if UEFI should be enabled
find_first_existing = { uefi_enabled = (
for path in local.uefi_firmware_paths : var.uefi_firmware == "true" ||
path => true if fileexists(path) var.uefi_firmware == true ||
} (var.uefi_firmware != "" && var.uefi_firmware != false && var.uefi_firmware != null)
)
# Function to get first available firmware path or null # Function to get first available firmware path or null
detected_firmware = ( detected_firmware = (
var.uefi_firmware == "true" || var.uefi_firmware == "" ? ( local.uefi_enabled ? (
length(local.find_first_existing) > 0 ? length(local.uefi_firmware_paths) > 0 ? (
keys(local.find_first_existing)[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
var.uefi_firmware != "" ? var.uefi_firmware : null ) : null
)
) )
# Same for NV-RAM template # Function to get first available NVRAM template or null
find_first_nvram = {
for path in local.uefi_nvram_paths :
path => true if fileexists(path)
}
detected_nvram = ( detected_nvram = (
var.uefi_firmware == "true" || var.uefi_firmware == "" ? ( local.uefi_enabled ? (
length(local.find_first_nvram) > 0 ? length(local.uefi_nvram_paths) > 0 ? (
keys(local.find_first_nvram)[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
var.uefi_nvram_template != "" ? var.uefi_nvram_template : null ) : null
)
)
# Validate that both firmware and NVRAM are provided together if one is specified
firmware_and_nvram_valid = (
(local.detected_firmware != null && local.detected_nvram == null) ||
(local.detected_firmware == null && local.detected_nvram == null) ||
(local.detected_firmware != null && local.detected_nvram != null)
) )
} }