Compare commits
21 Commits
3c8120a733
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8266670f1d | ||
|
|
7b67ff510b | ||
|
|
4aa7dafe26 | ||
|
|
ebaf28040c | ||
|
|
d6e11a3e63 | ||
|
|
f27930a294 | ||
|
|
1b757a98eb | ||
|
|
5f5119db1d | ||
|
|
f541ae77ce | ||
|
|
cdfae5661e | ||
|
|
ab633d601d | ||
|
|
4272105dd2 | ||
|
|
15dff2b43e | ||
|
|
5985b0f353 | ||
|
|
a5ae234469 | ||
|
|
94f2fd43ed | ||
|
|
ca2e84496a | ||
|
|
87dc196f77 | ||
|
|
8271e05336 | ||
|
|
7317e390c9 | ||
|
|
92404ccc34 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -10,7 +10,4 @@ terraform.tfvars.example
|
|||||||
# Terraform plan and output files
|
# Terraform plan and output files
|
||||||
*.tfplan
|
*.tfplan
|
||||||
*.tfout
|
*.tfout
|
||||||
|
.aider*
|
||||||
|
|
||||||
# Aider files
|
|
||||||
*.aider*
|
|
||||||
|
|||||||
22
environments/centos-10-cloud-bios/main.tf
Normal file
22
environments/centos-10-cloud-bios/main.tf
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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 = "cent10-bios"
|
||||||
|
image_location = "https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2"
|
||||||
|
ssh_key = "" # please provide a SSH public key
|
||||||
|
enable_cloudinit = true
|
||||||
|
}
|
||||||
22
environments/debian-13-cloud-bios/main.tf
Normal file
22
environments/debian-13-cloud-bios/main.tf
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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 = "deb-13-bios"
|
||||||
|
image_location = "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
||||||
|
ssh_key = "" # please provide a SSH public key
|
||||||
|
enable_cloudinit = true
|
||||||
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
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 = "deb-13-bios"
|
|
||||||
image_location = "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
|
||||||
ssh_key = ""
|
|
||||||
enable_cloudinit = true
|
|
||||||
# ---- UEFI SETTINGS ----------------------------------------------
|
|
||||||
# uefi_firmware = "/usr/share/edk2/ovmf/OVMF_CODE.fd" # Location on Fedora
|
|
||||||
# uefi_nvram_template = "/usr/share/edk2/ovmf/OVMF_VARS.fd" # Location on Fedora
|
|
||||||
uefi_firmware = "/usr/share/edk2/x64/OVMF_CODE.4m.fd" # Location on Arch Linux
|
|
||||||
uefi_nvram_template = "/usr/share/edk2/x64/OVMF_VARS.4m.fd" # Location on Arch Linux
|
|
||||||
uefi_nvram_file_suffix = "-uefi"
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
|
|
||||||
}
|
|
||||||
22
environments/fedora-cloud-rawhide-bios/main.tf
Normal file
22
environments/fedora-cloud-rawhide-bios/main.tf
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
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 = "fraw-bios"
|
||||||
|
image_location = "file:///var/lib/libvirt/images/Fedora-Cloud-Base-Generic-Rawhide-20251024.n.0.x86_64.qcow2"
|
||||||
|
ssh_key = "" # please provide a SSH public key
|
||||||
|
enable_cloudinit = true
|
||||||
|
}
|
||||||
@@ -17,6 +17,6 @@ module "shared_modules" {
|
|||||||
|
|
||||||
vm_name = "f42-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"
|
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_key = "" # please provide a SSH public key
|
||||||
enable_cloudinit = true
|
enable_cloudinit = true
|
||||||
}
|
}
|
||||||
@@ -17,14 +17,7 @@ module "shared_modules" {
|
|||||||
|
|
||||||
vm_name = "os-tw-uefi"
|
vm_name = "os-tw-uefi"
|
||||||
image_location = "https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2"
|
image_location = "https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2"
|
||||||
ssh_key = ""
|
ssh_key = "" # please provide a SSH public key
|
||||||
enable_cloudinit = true
|
enable_cloudinit = true
|
||||||
# ---- UEFI SETTINGS ----------------------------------------------
|
|
||||||
# uefi_firmware = "/usr/share/edk2/ovmf/OVMF_CODE.fd" # Location on Fedora
|
|
||||||
# uefi_nvram_template = "/usr/share/edk2/ovmf/OVMF_VARS.fd" # Location on Fedora
|
|
||||||
uefi_firmware = "/usr/share/edk2/x64/OVMF_CODE.4m.fd" # Location on Arch Linux
|
|
||||||
uefi_nvram_template = "/usr/share/edk2/x64/OVMF_VARS.4m.fd" # Location on Arch Linux
|
|
||||||
uefi_nvram_file_suffix = "-uefi"
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,11 +17,5 @@ module "shared_modules" {
|
|||||||
|
|
||||||
vm_name = "phyllome-42-uefi"
|
vm_name = "phyllome-42-uefi"
|
||||||
image_location = "/var/lib/libvirt/images/virtual-desktop-hypervisor.img"
|
image_location = "/var/lib/libvirt/images/virtual-desktop-hypervisor.img"
|
||||||
enable_cloudinit = false
|
uefi_firmware = 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"
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ module "shared_modules" {
|
|||||||
|
|
||||||
vm_name = "rl-bios"
|
vm_name = "rl-bios"
|
||||||
image_location = "https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
image_location = "https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
||||||
ssh_key = ""
|
ssh_key = "" # please provide a SSH public key
|
||||||
enable_cloudinit = true
|
enable_cloudinit = true
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,6 @@ module "shared_modules" {
|
|||||||
|
|
||||||
vm_name = "u24-bios"
|
vm_name = "u24-bios"
|
||||||
image_location = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
image_location = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||||
ssh_key = ""
|
ssh_key = "" # please provide a SSH public key
|
||||||
enable_cloudinit = true
|
enable_cloudinit = true
|
||||||
}
|
}
|
||||||
@@ -17,14 +17,7 @@ module "shared_modules" {
|
|||||||
|
|
||||||
vm_name = "u24-uefi"
|
vm_name = "u24-uefi"
|
||||||
image_location = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
image_location = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||||
ssh_key = ""
|
ssh_key = "" # please provide a SSH public key
|
||||||
enable_cloudinit = true
|
enable_cloudinit = true
|
||||||
# ---- UEFI SETTINGS ----------------------------------------------
|
uefi_firmware = true
|
||||||
uefi_firmware = "/usr/share/edk2/ovmf/OVMF_CODE.fd" # Location on Fedora
|
|
||||||
uefi_nvram_template = "/usr/share/edk2/ovmf/OVMF_VARS.fd" # Location on Fedora
|
|
||||||
# uefi_firmware = "/usr/share/edk2/x64/OVMF_CODE.4m.fd" # Location on Arch Linux
|
|
||||||
# uefi_nvram_template = "/usr/share/edk2/x64/OVMF_VARS.4m.fd" # Location on Arch Linux
|
|
||||||
uefi_nvram_file_suffix = "-uefi"
|
|
||||||
# ----------------------------------------------------------------
|
|
||||||
|
|
||||||
}
|
}
|
||||||
128
scripts/download_images.sh
Executable file
128
scripts/download_images.sh
Executable file
@@ -0,0 +1,128 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Function to get latest Fedora Rawhide image URL using a more reliable method
|
||||||
|
get_fedora_latest_rawhide_url() {
|
||||||
|
local base_url="https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Cloud/x86_64/images/"
|
||||||
|
|
||||||
|
# Method 1: Try fetching the latest link from the directory
|
||||||
|
local temp_dir
|
||||||
|
temp_dir=$(mktemp -d)
|
||||||
|
|
||||||
|
# Download the HTML directory listing
|
||||||
|
if curl -s -o "$temp_dir/listing.html" "$base_url"; then
|
||||||
|
# Look for lines with qcow2 files that match our pattern
|
||||||
|
local latest_file
|
||||||
|
latest_file=$(grep -i "Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2" "$temp_dir/listing.html" | \
|
||||||
|
sort -r | head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
||||||
|
|
||||||
|
if [[ -n "$latest_file" ]]; then
|
||||||
|
echo "${base_url}${latest_file}"
|
||||||
|
else
|
||||||
|
# If we can't find a specific file, try to find any valid Fedora image
|
||||||
|
local any_file
|
||||||
|
any_file=$(grep -i "Fedora-Cloud-Base-Generic.*\.qcow2" "$temp_dir/listing.html" | \
|
||||||
|
head -1 | sed -E 's/.*href="([^"]*)".*/\1/')
|
||||||
|
|
||||||
|
if [[ -n "$any_file" ]]; then
|
||||||
|
echo "${base_url}${any_file}"
|
||||||
|
else
|
||||||
|
# Return empty string if we can't find any valid file
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# If network fails, return empty string to skip Fedora download
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -rf "$temp_dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Image URLs with dynamic Fedora URL handling
|
||||||
|
IMAGES=(
|
||||||
|
"https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw"
|
||||||
|
"https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2"
|
||||||
|
"https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2"
|
||||||
|
"https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2"
|
||||||
|
"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
||||||
|
"https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add Fedora image if we can get a valid URL
|
||||||
|
FEDORA_URL=$(get_fedora_latest_rawhide_url)
|
||||||
|
if [[ -n "$FEDORA_URL" ]]; then
|
||||||
|
IMAGES+=("$FEDORA_URL")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Target directory
|
||||||
|
TARGET_DIR="/var/lib/libvirt/images"
|
||||||
|
|
||||||
|
# Main script execution
|
||||||
|
main() {
|
||||||
|
# Check if we have write permissions to the target directory
|
||||||
|
if [[ ! -w "$TARGET_DIR" ]]; then
|
||||||
|
# Check if we're already running as root
|
||||||
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
echo "This script requires write access to $TARGET_DIR"
|
||||||
|
echo "Re-executing with sudo..."
|
||||||
|
exec sudo "$0" "$@"
|
||||||
|
else
|
||||||
|
echo "Error: Cannot write to $TARGET_DIR even with sudo privileges."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Download all images
|
||||||
|
echo "Starting download of all images..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
local success_count=0
|
||||||
|
local failure_count=0
|
||||||
|
|
||||||
|
for url in "${IMAGES[@]}"; do
|
||||||
|
# Skip empty URLs
|
||||||
|
if [[ -z "$url" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
local filename
|
||||||
|
filename=$(basename "$url")
|
||||||
|
local filepath="$TARGET_DIR/$filename"
|
||||||
|
|
||||||
|
if [[ -f "$filepath" ]]; then
|
||||||
|
echo "Image $filename already exists, skipping..."
|
||||||
|
((success_count++))
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Downloading $filename..."
|
||||||
|
|
||||||
|
# Use wget with progress and retry options
|
||||||
|
if ! wget -P "$TARGET_DIR" --progress=bar:force:noscroll -c "$url"; then
|
||||||
|
echo "Failed to download $filename"
|
||||||
|
((failure_count++))
|
||||||
|
else
|
||||||
|
echo "Download completed: $filename"
|
||||||
|
((success_count++))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
echo ""
|
||||||
|
echo "Download summary:"
|
||||||
|
echo "Successful downloads: $success_count"
|
||||||
|
echo "Failed downloads: $failure_count"
|
||||||
|
|
||||||
|
if [[ $failure_count -gt 0 ]]; then
|
||||||
|
echo "Some downloads failed. Check above messages for details."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "All images downloaded successfully!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main function if script is executed directly
|
||||||
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
302
scripts/update_image_locations.sh
Executable file
302
scripts/update_image_locations.sh
Executable file
@@ -0,0 +1,302 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script to detect locally available OS images and update image_location URLs in main.tf files
|
||||||
|
# This script updates terraform configurations to use local image paths instead of remote URLs
|
||||||
|
# It also supports reverting back to original remote URLs using hardcoded values
|
||||||
|
|
||||||
|
# Function to display usage
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 [options]"
|
||||||
|
echo " options:"
|
||||||
|
echo " -h, --help Display this help message"
|
||||||
|
echo " -d, --dry-run Show what would be changed without making modifications"
|
||||||
|
echo " -r, --revert Revert image_location URLs back to original remote URLs"
|
||||||
|
echo ""
|
||||||
|
echo "Example:"
|
||||||
|
echo " $0 # Convert remote URLs to local paths (default)"
|
||||||
|
echo " $0 -d # Dry run - show what would be updated"
|
||||||
|
echo " $0 -r # Revert to original remote URLs"
|
||||||
|
echo " $0 -r -d # Dry run revert mode"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
DRY_RUN=false
|
||||||
|
REVERT_MODE=false
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
-d|--dry-run)
|
||||||
|
DRY_RUN=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-r|--revert)
|
||||||
|
REVERT_MODE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1"
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Define the directory where images are stored
|
||||||
|
IMAGE_DIR="/var/lib/libvirt/images"
|
||||||
|
|
||||||
|
# Check if we have write permissions to the target directory
|
||||||
|
if [[ ! -d "$IMAGE_DIR" ]]; then
|
||||||
|
echo "Error: Directory $IMAGE_DIR does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Function to get all locally available image files (including Fedora Rawhide)
|
||||||
|
get_local_images() {
|
||||||
|
find "$IMAGE_DIR" -maxdepth 1 -type f \( -name "*.qcow2" -o -name "*.raw" -o -name "*.img" \) | \
|
||||||
|
while read -r image; do
|
||||||
|
basename "$image"
|
||||||
|
done | sort
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to check if a local file matches the pattern for a Fedora Rawhide image
|
||||||
|
is_fedora_rawhide_image() {
|
||||||
|
local filename=$1
|
||||||
|
# Pattern matching for Fedora Rawhide images that contain "Fedora-Cloud-Base-Generic-Rawhide"
|
||||||
|
if [[ "$filename" =~ ^Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2$ ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to get the latest Fedora Rawhide image path from local directory
|
||||||
|
get_latest_fedora_rawhide_path() {
|
||||||
|
local latest_file
|
||||||
|
latest_file=$(find "$IMAGE_DIR" -maxdepth 1 -name "Fedora-Cloud-Base-Generic-Rawhide*.qcow2" -type f \
|
||||||
|
| sort -r \
|
||||||
|
| head -1)
|
||||||
|
|
||||||
|
if [[ -n "$latest_file" ]]; then
|
||||||
|
echo "$latest_file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to provide a mapping between local files and their original URLs
|
||||||
|
create_original_url_mapping() {
|
||||||
|
# Create a hash-like mapping for known images
|
||||||
|
cat << 'EOF'
|
||||||
|
noble-server-cloudimg-amd64.img=https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
|
||||||
|
Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2=https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2
|
||||||
|
openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2=https://download.opensuse.org/tumbleweed/appliances/openSUSE-Tumbleweed-Minimal-VM.x86_64-Cloud.qcow2
|
||||||
|
Rocky-10-GenericCloud-Base.latest.x86_64.qcow2=https://dl.rockylinux.org/pub/rocky/10/images/x86_64/Rocky-10-GenericCloud-Base.latest.x86_64.qcow2
|
||||||
|
debian-13-genericcloud-amd64.raw=https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.raw
|
||||||
|
CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2=https://cloud.centos.org/centos/10-stream/x86_64/images/CentOS-Stream-GenericCloud-x86_64-10-latest.x86_64.qcow2
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find all main.tf files and process them
|
||||||
|
MAIN_TF_FILES=$(find . -name "main.tf" -type f)
|
||||||
|
|
||||||
|
if [ -z "$MAIN_TF_FILES" ]; then
|
||||||
|
echo "No main.tf files found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Found main.tf files:"
|
||||||
|
echo "$MAIN_TF_FILES"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Process each file
|
||||||
|
for file in $MAIN_TF_FILES; do
|
||||||
|
echo "Processing $file..."
|
||||||
|
|
||||||
|
# Check if the file contains image_location lines
|
||||||
|
if ! grep -q "image_location" "$file"; then
|
||||||
|
echo " No image_location found in $file, skipping..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$REVERT_MODE" = true ]; then
|
||||||
|
# Revert operation: change file:// back to original https:// URLs
|
||||||
|
temp_file=$(mktemp)
|
||||||
|
|
||||||
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
|
# Check if the line contains a file:// URL
|
||||||
|
if [[ "$line" =~ .*image_location.*=.*\"file://(.*?)\".* ]]; then
|
||||||
|
# Extract local path from the file:// URL
|
||||||
|
local_file_path="${BASH_REMATCH[1]}"
|
||||||
|
local_filename=$(basename "$local_file_path")
|
||||||
|
|
||||||
|
# Handle Fedora Rawhide images specially
|
||||||
|
if [[ "$local_filename" =~ ^Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2$ ]]; then
|
||||||
|
echo " Reverting Fedora Rawhide image: $local_filename"
|
||||||
|
|
||||||
|
# For Rawhide, we'll keep the file:// reference but note that it's a special case
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
else
|
||||||
|
echo " Would process Fedora Rawhide image: $local_filename (keeping file:// reference)"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# For regular images, try to map back to original URL
|
||||||
|
# Create mapping for this specific case
|
||||||
|
mapping=$(create_original_url_mapping)
|
||||||
|
|
||||||
|
# Find matching original URL
|
||||||
|
found_match=false
|
||||||
|
while IFS= read -r mapping_line; do
|
||||||
|
if [[ -z "$mapping_line" ]] || [[ "$mapping_line" =~ ^#.*$ ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
file_pattern=$(echo "$mapping_line" | cut -d'=' -f1)
|
||||||
|
original_url=$(echo "$mapping_line" | cut -d'=' -f2)
|
||||||
|
|
||||||
|
if [[ "$file_pattern" == "$local_filename" ]]; then
|
||||||
|
echo " Found matching original URL: $local_filename"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
# Use precise string replacement to avoid corrupting the file
|
||||||
|
new_line="${line/\"file:\/\/$local_file_path\"/\"$original_url\"}"
|
||||||
|
echo "$new_line" >> "$temp_file"
|
||||||
|
echo " Reverted to original URL: $original_url"
|
||||||
|
else
|
||||||
|
echo " Would revert to: $original_url"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
found_match=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done <<< "$mapping"
|
||||||
|
|
||||||
|
if [ "$found_match" = false ]; then
|
||||||
|
echo " Warning: No matching original URL found for $local_filename"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Not a line with image_location, just copy as is
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
done < "$file"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
mv "$temp_file" "$file"
|
||||||
|
else
|
||||||
|
rm "$temp_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
# Normal operation: convert remote URLs to local paths
|
||||||
|
temp_file=$(mktemp)
|
||||||
|
|
||||||
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
|
if [[ "$line" =~ .*image_location.*=.*\"(https://.*)\".* ]]; then
|
||||||
|
remote_url="${BASH_REMATCH[1]}"
|
||||||
|
filename=$(basename "$remote_url")
|
||||||
|
|
||||||
|
# Check if the local file exists (including Fedora Rawhide cases)
|
||||||
|
local_path="$IMAGE_DIR/$filename"
|
||||||
|
|
||||||
|
# Special handling for Fedora Rawhide - check if it's the right pattern
|
||||||
|
if [[ "$filename" =~ ^Fedora-Cloud-Base-Generic-Rawhide.*\.qcow2$ ]]; then
|
||||||
|
# For Fedora Rawhide, we need to be more flexible with matching patterns
|
||||||
|
echo " Checking Fedora Rawhide pattern for: $filename"
|
||||||
|
|
||||||
|
# Find the most recent Fedora image that matches the pattern but has different timestamp
|
||||||
|
latest_rawhide=$(find "$IMAGE_DIR" -maxdepth 1 -name "Fedora-Cloud-Base-Generic-Rawhide*.qcow2" -type f \
|
||||||
|
| sort -r \
|
||||||
|
| head -1)
|
||||||
|
|
||||||
|
if [[ -n "$latest_rawhide" ]]; then
|
||||||
|
echo " Found matching local Fedora Rawhide image: $(basename $latest_rawhide)"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
new_line="${line/\"$remote_url\"/\"file://$latest_rawhide\"}"
|
||||||
|
echo "$new_line" >> "$temp_file"
|
||||||
|
echo " Updated to local file: file://$latest_rawhide"
|
||||||
|
else
|
||||||
|
echo " Would update Fedora Rawhide to: file://$latest_rawhide"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# No matching locally - check if we can find a similar pattern
|
||||||
|
echo " Checking for any Fedora-Cloud-Base-Generic-Rawhide*.qcow2 files..."
|
||||||
|
# Look for any file with the same prefix but different timestamp
|
||||||
|
local_candidates=$(find "$IMAGE_DIR" -maxdepth 1 -name "*Fedora-Cloud-Base-Generic-Rawhide*" -type f)
|
||||||
|
|
||||||
|
if [[ -n "$local_candidates" ]]; then
|
||||||
|
most_recent=$(echo "$local_candidates" | sort -r | head -1)
|
||||||
|
echo " Found matching local Fedora Rawhide image: $(basename $most_recent)"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
new_line="${line/\"$remote_url\"/\"file://$most_recent\"}"
|
||||||
|
echo "$new_line" >> "$temp_file"
|
||||||
|
echo " Updated to local file: file://$most_recent"
|
||||||
|
else
|
||||||
|
echo " Would update Fedora Rawhide to: file://$most_recent"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " Local Fedora Rawhide image not found, using original URL"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
elif [[ -f "$local_path" ]]; then
|
||||||
|
echo " Found local image: $filename"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
# Use precise string replacement to avoid corrupting the file
|
||||||
|
new_line="${line/\"$remote_url\"/\"file://$local_path\"}"
|
||||||
|
echo "$new_line" >> "$temp_file"
|
||||||
|
echo " Updated to: file://$local_path"
|
||||||
|
else
|
||||||
|
echo " Would update to: file://$local_path"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " Local image not found: $filename"
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Not a line with image_location, just copy as is
|
||||||
|
echo "$line" >> "$temp_file"
|
||||||
|
fi
|
||||||
|
done < "$file"
|
||||||
|
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
mv "$temp_file" "$file"
|
||||||
|
else
|
||||||
|
rm "$temp_file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
if [ "$DRY_RUN" = false ]; then
|
||||||
|
if [ "$REVERT_MODE" = true ]; then
|
||||||
|
echo "Image location URLs have been successfully reverted to original remote URLs!"
|
||||||
|
else
|
||||||
|
echo "Image location URLs have been successfully updated in all main.tf files!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Dry run completed - no changes were made."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show a summary of what would be changed
|
||||||
|
echo ""
|
||||||
|
echo "Summary of local image availability:"
|
||||||
|
find "$IMAGE_DIR" -maxdepth 1 -type f -name "*.qcow2" -o -name "*.raw" -o -name "*.img" | \
|
||||||
|
while read -r image; do
|
||||||
|
filename=$(basename "$image")
|
||||||
|
echo " ✓ $filename"
|
||||||
|
done
|
||||||
|
|
||||||
|
# If nothing was found, show what images are expected
|
||||||
|
if ! find "$IMAGE_DIR" -maxdepth 1 -type f -name "*.qcow2" -o -name "*.raw" -o -name "*.img" | grep -q .; then
|
||||||
|
echo " No local images found in $IMAGE_DIR"
|
||||||
|
echo " Run download_images.sh to download required images."
|
||||||
|
fi
|
||||||
@@ -20,19 +20,15 @@ resource "libvirt_domain" "domain" {
|
|||||||
|
|
||||||
# ---- optional UEFI support ------------------------------------
|
# ---- optional UEFI support ------------------------------------
|
||||||
# Firmware – only add the string when a path is supplied
|
# Firmware – only add the string when a path is supplied
|
||||||
firmware = can(var.uefi_firmware) && length(var.uefi_firmware) > 0 ? var.uefi_firmware : null
|
firmware = local.detected_firmware
|
||||||
|
|
||||||
# NVRAM block – dynamic block that is evaluated once per VM
|
# NVRAM block – dynamic block that is evaluated once per VM
|
||||||
dynamic "nvram" {
|
dynamic "nvram" {
|
||||||
# create the block once if a firmware path *and* a template were given
|
for_each = (local.detected_firmware != null && local.detected_nvram != null) ? [1] : []
|
||||||
for_each = (can(var.uefi_firmware) && length(var.uefi_firmware) > 0
|
|
||||||
&& can(var.uefi_nvram_template) && length(var.uefi_nvram_template) > 0
|
|
||||||
) ? [1] : []
|
|
||||||
|
|
||||||
content {
|
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"
|
file = "/var/lib/libvirt/qemu/nvram/${var.vm_name}-${count.index}${var.uefi_nvram_file_suffix}_VARS.fd"
|
||||||
template = var.uefi_nvram_template
|
template = local.detected_nvram
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ variable "pool_name" {
|
|||||||
variable "pool_path" {
|
variable "pool_path" {
|
||||||
description = "Path for the storage pool"
|
description = "Path for the storage pool"
|
||||||
type = string
|
type = string
|
||||||
default = "/tmp/tf_tmp_storage"
|
default = "/opt/tf_tmp_storage"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instance_count" {
|
variable "instance_count" {
|
||||||
@@ -71,7 +71,7 @@ variable "memory" {
|
|||||||
variable "vcpu" {
|
variable "vcpu" {
|
||||||
description = "Number of virtual CPUs"
|
description = "Number of virtual CPUs"
|
||||||
type = number
|
type = number
|
||||||
default = 2
|
default = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "network_mode" {
|
variable "network_mode" {
|
||||||
@@ -105,23 +105,26 @@ variable "dns_local_only" {
|
|||||||
default = false
|
default = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Improved UEFI variables with automatic detection
|
||||||
|
# For backward compatibility with the current module interface
|
||||||
variable "uefi_firmware" {
|
variable "uefi_firmware" {
|
||||||
description = <<EOT
|
description = <<EOT
|
||||||
Path to the UEFI firmware binary (OVMF_CODE.fd, QEMU_CODE.fd, …).
|
Enable UEFI support. Set to true to enable UEFI with auto-detected firmware,
|
||||||
Leave empty (or omit on the module call) to create a plain BIOS VM.
|
or provide a specific path to the firmware binary.
|
||||||
|
Set to false or omit to create a plain BIOS VM.
|
||||||
EOT
|
EOT
|
||||||
type = string
|
type = string
|
||||||
default = "" # “BIOS only” when empty
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "uefi_nvram_template" {
|
variable "uefi_nvram_template" {
|
||||||
description = <<EOT
|
description = <<EOT
|
||||||
Path to an NV‑RAM template that backs the UEFI NVRAM.
|
Path to an NV‑RAM template that backs the UEFI NVRAM.
|
||||||
If you specify a template, the VM will get a writable NVRAM block.
|
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.
|
Leave empty for a plain BIOS VM or if you don't need UEFI NVRAM.
|
||||||
EOT
|
EOT
|
||||||
type = string
|
type = string
|
||||||
default = "" # no NVRAM when empty
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "uefi_nvram_file_suffix" {
|
variable "uefi_nvram_file_suffix" {
|
||||||
@@ -138,4 +141,56 @@ variable "uefi_nvram_file_suffix" {
|
|||||||
# 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"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user