Changing domain to null resource
This commit is contained in:
parent
ecbce27540
commit
bacaa27c0b
1 changed files with 40 additions and 24 deletions
|
|
@ -42,7 +42,7 @@ variable "talos_version" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "libvirt_network" "talos_bridge" {
|
resource "libvirt_network" "talos_bridge" {
|
||||||
name = "my-talos-net"
|
name = "control-plane-net"
|
||||||
autostart = true
|
autostart = true
|
||||||
|
|
||||||
xml {
|
xml {
|
||||||
|
|
@ -50,8 +50,8 @@ resource "libvirt_network" "talos_bridge" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "libvirt_pool" "images" {
|
resource "libvirt_pool" "talos-images" {
|
||||||
name = "images"
|
name = "talos-images"
|
||||||
type = "dir"
|
type = "dir"
|
||||||
target {
|
target {
|
||||||
path = "/var/lib/libvirt/images/talos-kvm"
|
path = "/var/lib/libvirt/images/talos-kvm"
|
||||||
|
|
@ -61,7 +61,7 @@ resource "libvirt_pool" "images" {
|
||||||
# Download the ISO
|
# Download the ISO
|
||||||
resource "libvirt_volume" "talos_iso" {
|
resource "libvirt_volume" "talos_iso" {
|
||||||
name = "talos-metal-arm64.iso"
|
name = "talos-metal-arm64.iso"
|
||||||
pool = "images"
|
pool = "talos-images"
|
||||||
source = "https://factory.talos.dev/image/4a0d65c669d46663f377e7161e50cfd570c401f26fd9e7bda34a0216b6f1922b/v1.11.1/metal-arm64.iso"
|
source = "https://factory.talos.dev/image/4a0d65c669d46663f377e7161e50cfd570c401f26fd9e7bda34a0216b6f1922b/v1.11.1/metal-arm64.iso"
|
||||||
format = "raw"
|
format = "raw"
|
||||||
}
|
}
|
||||||
|
|
@ -69,37 +69,53 @@ resource "libvirt_volume" "talos_iso" {
|
||||||
# Create disk for VM
|
# Create disk for VM
|
||||||
resource "libvirt_volume" "control_plane_disk" {
|
resource "libvirt_volume" "control_plane_disk" {
|
||||||
name = "control-plane-node-1-disk.qcow2"
|
name = "control-plane-node-1-disk.qcow2"
|
||||||
pool = "images"
|
pool = "talos-images"
|
||||||
base_volume_id = libvirt_volume.talos_iso.id
|
base_volume_id = libvirt_volume.talos_iso.id
|
||||||
size = 42949672960 # 40GB in bytes
|
size = 42949672960 # 40GB in bytes
|
||||||
format = "qcow2"
|
format = "qcow2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create the VM
|
# Create the VM
|
||||||
resource "libvirt_domain" "control_plane_node_1" {
|
resource "null_resource" "control_plane_node_1" {
|
||||||
name = "control-plane-node-1"
|
depends_on = [
|
||||||
memory = 2048
|
libvirt_network.talos_bridge,
|
||||||
vcpu = 2
|
libvirt_volume.control_plane_disk,
|
||||||
|
libvirt_volume.talos_iso
|
||||||
|
]
|
||||||
|
|
||||||
disk {
|
triggers = {
|
||||||
volume_id = libvirt_volume.control_plane_disk.id
|
cpus = var.vcpu_count,
|
||||||
|
memory = var.memory_mb,
|
||||||
|
cluster_name = var.cluster_name
|
||||||
}
|
}
|
||||||
|
|
||||||
disk {
|
provisioner "local-exec" {
|
||||||
file = libvirt_volume.talos_iso.id
|
command = <<EOT
|
||||||
|
virt-install \
|
||||||
|
--connect=qemu:///system \
|
||||||
|
--virt-type kvm \
|
||||||
|
--name ${self.triggers.cluster_name} \
|
||||||
|
--ram ${self.triggers.memory} \
|
||||||
|
--vcpus ${self.triggers.cpus} \
|
||||||
|
--disk path=/var/lib/libvirt/images/talos-kvm/control-plane-node-1-disk.qcow2,bus=virtio,size=40,format=qcow2 \
|
||||||
|
--cdrom /var/lib/libvirt/images/talos-kvm/metal-arm64.iso \
|
||||||
|
--os-variant=linux2022 \
|
||||||
|
--network network=control-plane-net \
|
||||||
|
--graphics none \
|
||||||
|
--boot hd,cdrom \
|
||||||
|
--noautoconsole
|
||||||
|
|
||||||
|
virsh --connect=qemu:///system autostart ${self.triggers.cluster_name}
|
||||||
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
network_interface {
|
provisioner "local-exec" {
|
||||||
network_name = "my-talos-net"
|
when = destroyed
|
||||||
}
|
|
||||||
|
|
||||||
graphics {
|
command = <<EOT
|
||||||
type = "none"
|
sudo rm -f /var/lib/libvirt/qemu/nvram/${self.triggers.cluster_name}_VARS.qcow2
|
||||||
|
virsh --connect=qemu:///system destroy ${self.triggers.cluster_name}
|
||||||
|
virsh --connect=qemu:///system undefine --remove-all-storage ${self.triggers.cluster_name}
|
||||||
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_device {
|
|
||||||
dev = ["hd", "cdrom"]
|
|
||||||
}
|
|
||||||
|
|
||||||
autostart = true
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue