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:
@@ -106,6 +106,7 @@ variable "dns_local_only" {
|
||||
}
|
||||
|
||||
# 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,
|
||||
@@ -137,11 +138,10 @@ variable "uefi_nvram_file_suffix" {
|
||||
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",
|
||||
@@ -165,43 +165,32 @@ locals {
|
||||
"/usr/share/ovmf/OVMF_VARS.fd"
|
||||
]
|
||||
|
||||
# Helper function to find first existing file
|
||||
find_first_existing = {
|
||||
for path in local.uefi_firmware_paths :
|
||||
path => true if fileexists(path)
|
||||
}
|
||||
# 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 = (
|
||||
var.uefi_firmware == "true" || var.uefi_firmware == "" ? (
|
||||
length(local.find_first_existing) > 0 ?
|
||||
keys(local.find_first_existing)[0] :
|
||||
null
|
||||
) : (
|
||||
var.uefi_firmware != "" ? var.uefi_firmware : null
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
# Same for NV-RAM template
|
||||
find_first_nvram = {
|
||||
for path in local.uefi_nvram_paths :
|
||||
path => true if fileexists(path)
|
||||
}
|
||||
|
||||
# Function to get first available NVRAM template or null
|
||||
detected_nvram = (
|
||||
var.uefi_firmware == "true" || var.uefi_firmware == "" ? (
|
||||
length(local.find_first_nvram) > 0 ?
|
||||
keys(local.find_first_nvram)[0] :
|
||||
null
|
||||
) : (
|
||||
var.uefi_nvram_template != "" ? var.uefi_nvram_template : 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)
|
||||
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
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user