1
0
This commit is contained in:
michael 2022-10-04 02:47:03 +13:00
parent 2cfb3b180f
commit ae8633767a
6 changed files with 38 additions and 23 deletions

View File

@ -3,6 +3,8 @@ checksum_url = "https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x8
host_ssh_user = "michael" host_ssh_user = "michael"
host_ssh_address = "server.balsillie.net" host_ssh_address = "server.balsillie.net"
host_ssh_private_key = "/home/michael/.ssh/conf.d/home/michael_server_copy.key"
host_ssh_known_hosts = "/home/michael/.ssh/known_hosts_server"
guest_hostname = "arch-minimal-template" guest_hostname = "arch-minimal-template"
cpu_count = 2 cpu_count = 2
@ -12,7 +14,7 @@ arch = "x86_64"
chipset = "pc-q35-6.1" chipset = "pc-q35-6.1"
loader_type = "pflash" loader_type = "pflash"
loader_path = "/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd" loader_path = "/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd"
secure_boot = true secure_boot = false
nvram_template = "/usr/share/edk2-ovmf/x64/OVMF_VARS.fd" nvram_template = "/usr/share/edk2-ovmf/x64/OVMF_VARS.fd"
nvram_path_base = "/var/lib/libvirt/qemu/nvram" nvram_path_base = "/var/lib/libvirt/qemu/nvram"
@ -26,7 +28,7 @@ ssh_source = "192.168.20.0/24"
guest_ssh_user = "arch" guest_ssh_user = "arch"
guest_ssh_port = 22 guest_ssh_port = 22
guest_ssh_private_key = "~/.ssh/conf.d/home/arch@arch_template.key" guest_ssh_private_key = "/home/michael/.ssh/conf.d/home/arch@arch_template.key"
guest_ssh_public_key = "~/.ssh/conf.d/home/arch@arch_template.key.pub" guest_ssh_public_key = "~/.ssh/conf.d/home/arch@arch_template.key.pub"
network_address = "192.168.21.200/24" network_address = "192.168.21.200/24"

View File

@ -25,8 +25,8 @@ data "http" "image_checksum" {
} }
locals { locals {
image_checksum = split(" ",data.http.image_checksum)[0] image_checksum = split(" ",data.http.image_checksum.body)[0]
libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${var.host_ssh_address}/system" libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${var.host_ssh_address}/system?keyfile=${var.host_ssh_private_key}&no_verify=1"
nvram_path = "${var.nvram_path_base}/${var.guest_hostname}_VARS.fd" nvram_path = "${var.nvram_path_base}/${var.guest_hostname}_VARS.fd"
cidata_name = "${var.volume_name}_cidata" cidata_name = "${var.volume_name}_cidata"
} }
@ -47,8 +47,10 @@ source "libvirt" "arch-minimal" {
chipset = var.chipset chipset = var.chipset
loader_type = var.loader_type loader_type = var.loader_type
loader_path = var.loader_path loader_path = var.loader_path
nvram_template = var.nvmram_template // nvram_template = var.nvram_template
nvram_path = local.nvram_path // nvram_path = local.nvram_path
nvram_template = local.nvram_path
nvram_path = var.nvram_template
secure_boot = var.secure_boot secure_boot = var.secure_boot
volume { volume {
@ -65,6 +67,7 @@ source "libvirt" "arch-minimal" {
type = "external" type = "external"
urls = [var.image_url] urls = [var.image_url]
checksum = local.image_checksum checksum = local.image_checksum
// checksum = "f237ada9ba61431f6aebb066d2b3f0b5b432ea21da6034d98248725df1417545"
} }
} }
@ -77,8 +80,8 @@ source "libvirt" "arch-minimal" {
type = "cloud-init" type = "cloud-init"
meta_data = jsonencode({ meta_data = jsonencode({
"instance-id" = ${var.guest_hostname} "instance-id" = "${var.guest_hostname}"
"hostname" = ${var.guest_hostname} "hostname" = "${var.guest_hostname}"
}) })
user_data = format("#cloud-config\n%s", jsonencode({ user_data = format("#cloud-config\n%s", jsonencode({
@ -89,7 +92,7 @@ source "libvirt" "arch-minimal" {
"runcmd" = [ "runcmd" = [
["systemctl", "enable", "--now", "qemu-guest-agent"], ["systemctl", "enable", "--now", "qemu-guest-agent"],
["ufw", "enable"], ["ufw", "enable"],
["ufw", "allow", "from", ${var.ssh_source}, "to", "port", "22", "proto", "tcp"], ["ufw", "allow", "from", "${var.ssh_source}", "to", "port", "22", "proto", "tcp"],
["systemctl", "enable", "--now", "ufw"] ["systemctl", "enable", "--now", "ufw"]
] ]
})) }))
@ -103,16 +106,15 @@ source "libvirt" "arch-minimal" {
name = "en*" name = "en*"
} }
dhcp4 = false dhcp4 = false
addresses = [${var.network_address}] addresses = ["${var.network_address}"]
gateway4 = ${var.network_gateway} gateway4 = "${var.network_gateway}"
nameservers = { nameservers = {
addresses = [${var.network_nameserver}] addresses = ["${var.network_nameserver}"]
search = [${var.network_domain}] search = ["${var.network_domain}"]
} }
} }
} }
}) })
} }
} }
@ -127,14 +129,14 @@ source "libvirt" "arch-minimal" {
network_address_source = "agent" network_address_source = "agent"
graphics { graphics {
type = "spice" type = "vnc"
port = 5900 port = 5902
} }
communicator { communicator {
ssh_username = var.guest_ssh_user ssh_username = var.guest_ssh_user
ssh_port = var.guest_ssh_port ssh_port = var.guest_ssh_port
ssh_private_key = var.guest_ssh_private_key ssh_private_key_file = var.guest_ssh_private_key
} }
communicator_interface = "default-network" communicator_interface = "default-network"
} }

View File

@ -91,6 +91,7 @@ variable "guest_ssh_pass" {
type = string type = string
sensitive = true sensitive = true
description = "Password for SSH connection to the guest VM." description = "Password for SSH connection to the guest VM."
default = "placeholder"
} }
variable "guest_ssh_port" { variable "guest_ssh_port" {
@ -119,14 +120,24 @@ variable "ssh_source" {
description = "The subnet that will be added to the firewall SSH exception during cloud-init." description = "The subnet that will be added to the firewall SSH exception during cloud-init."
} }
variable "host_ssh_user" {
type = string
description = "The user to connect to the hypervisor as, used to construct the libvirt URI."
}
variable "host_ssh_address" { variable "host_ssh_address" {
type = string type = string
description = "The address of the hypervisor, used to construct the libvirt URI." description = "The address of the hypervisor, used to construct the libvirt URI."
} }
variable "host_ssh_user" { variable "host_ssh_private_key" {
type = string type = string
description = "The user to connect to the hypervisor as, used to construct the libvirt URI." description = "File path to the SSH key used to authenticate to the hypervisor host."
}
variable "host_ssh_known_hosts" {
type = string
description = "File path to the known_hosts file for validating the hypervisor host connection."
} }
variable "network_address" { variable "network_address" {