diff --git a/shared_modules/variables.tf b/shared_modules/variables.tf index 869ae14..c009216 100644 --- a/shared_modules/variables.tf +++ b/shared_modules/variables.tf @@ -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 = < 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 ) } \ No newline at end of file