1
0
This commit is contained in:
michael 2022-10-04 00:11:25 +13:00
parent 92a04af990
commit dac4962ace
3 changed files with 141 additions and 18 deletions

View File

@ -26,7 +26,7 @@ data "http" "image_checksum" {
locals { locals {
image_checksum = split(" ",data.http.image_checksum)[0] image_checksum = split(" ",data.http.image_checksum)[0]
libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${host_ssh_address}/system" libvirt_uri = "qemu+ssh://${var.host_ssh_user}@${var.host_ssh_address}/system"
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"
} }
@ -49,7 +49,7 @@ source "libvirt" "arch-minimal" {
loader_path = var.loader_path loader_path = var.loader_path
nvram_template = var.nvmram_template nvram_template = var.nvmram_template
nvram_path = local.nvram_path nvram_path = local.nvram_path
secure_boot = true secure_boot = var.secure_boot
volume { volume {
alias = "artifact" alias = "artifact"
@ -95,13 +95,20 @@ source "libvirt" "arch-minimal" {
})) }))
network_config = jsonencode({ network_config = jsonencode({
renderer = "networkd"
version = 2 version = 2
ethernets = { ethernets = {
eth = { eth0 = {
match = { match = {
name = "en*" name = "en*"
} }
dhcp4 = true dhcp4 = false
addresses = [${var.network_address}]
gateway4 = ${var.network_gateway}
nameservers = {
addresses = [${var.network_nameserver}]
search = [${var.network_domain}]
}
} }
} }
}) })

View File

@ -20,9 +20,16 @@ volume_name = "arch_minimal_template"
volume_pool = "default" volume_pool = "default"
volume_capacity = "30G" volume_capacity = "30G"
bridge_name = "br0" bridge_name = "br21"
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 = "~/.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_gateway = "192.168.20.254"
network_nameserver = "192.168.30.20"
network_domain = "balsillie.net"

View File

@ -8,11 +8,117 @@ variable "checksum_url" {
description = "The URL to retrieve the checksum value of the backing image from." description = "The URL to retrieve the checksum value of the backing image from."
} }
variable "hostname" { variable "cpu_count" {
type = number
description = "Number of vCPUs to create guest with."
}
variable "memory" {
type = number
description = "Amount of RAM in MiB to create guest with."
}
variable "domain_type" {
type = string
description = "Type of hypervisor to use."
default = "kvm"
}
variable "arch" {
type = string
description = "Domain architecture."
default = "x86_64"
}
variable "chipset" {
type = string
description = "Libvirt Machine Type Value for domain XML's machine type."
default = "q35"
}
variable "loader_type" {
type = string
description = "Where loader should be stored in guest. rom or pflash"
default = "pflash"
}
variable "loader_path" {
type = string
description = "File path where the OVMF firmware files are stored on the host."
}
variable "secure_boot" {
type = bool
description = "Whether to enable secure boot."
}
variable "nvram_template" {
type = string
description = "File path where the OVMF_VARS template file is stored on the host."
}
variable "nvram_path_base" {
type = string
description = "Parent dir where the guest OVMF_VARS copy will be stored. No trailing /"
}
variable "volume_name" {
type = string
description = "Name of the final template image artifact."
}
variable "volume_pool" {
type = string
description = "Host storage pool where the template image will be kept."
}
variable "volume_capacity" {
type = string
description = "Size of the template image drive."
}
variable "bridge_name" {
type = string
description = "Name of the bridge netdev on the host."
}
variable "guest_ssh_user" {
type = string
description = "User account for connecing to the guest VM, eg for provisioners."
}
variable "guest_ssh_pass" {
type = string
sensitive = true
description = "Password for SSH connection to the guest VM."
}
variable "guest_ssh_port" {
type = number
description = "SSH port for connecting to the guest VM."
default = 22
}
variable "guest_ssh_private_key" {
type = string
description = "File path to the private key used for SSH pubkey auth to the guest VM."
}
variable "guest_ssh_public_key" {
type = string
description = "File path to the public key to be added to authoried_keys on the guest VM during cloud-init."
}
variable "guest_hostname" {
type = string type = string
description = "The hostname of the virtual machine" description = "The hostname of the virtual machine"
} }
variable "ssh_source" {
type = string
description = "The subnet that will be added to the firewall SSH exception during cloud-init."
}
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."
@ -23,19 +129,22 @@ variable "host_ssh_user" {
description = "The user to connect to the hypervisor as, used to construct the libvirt URI." description = "The user to connect to the hypervisor as, used to construct the libvirt URI."
} }
variable "arch" { variable "network_address" {
type = string
description = "Domain architecture."
default = "x86_64"
}
variable "chipset" {
type = string type = string
description = "Libvirt Machine Type Value for domain XML's machine type." description = "Network address assigned to the guest."
} }
variable "guest_ssh_pass" { variable "network_gateway" {
type = string type = string
sensitive = true description = "Default gateway assigned to the guest."
description = "Default password for the cloud-init image" }
variable "network_nameserver" {
type = string
description = "DNS/Nameserver assigned to the guest."
}
variable "network_domain" {
type = string
description = "Search domain assigned to the guest."
} }