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" {
|
||||
name = "my-talos-net"
|
||||
name = "control-plane-net"
|
||||
autostart = true
|
||||
|
||||
xml {
|
||||
|
|
@ -50,8 +50,8 @@ resource "libvirt_network" "talos_bridge" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "libvirt_pool" "images" {
|
||||
name = "images"
|
||||
resource "libvirt_pool" "talos-images" {
|
||||
name = "talos-images"
|
||||
type = "dir"
|
||||
target {
|
||||
path = "/var/lib/libvirt/images/talos-kvm"
|
||||
|
|
@ -61,7 +61,7 @@ resource "libvirt_pool" "images" {
|
|||
# Download the ISO
|
||||
resource "libvirt_volume" "talos_iso" {
|
||||
name = "talos-metal-arm64.iso"
|
||||
pool = "images"
|
||||
pool = "talos-images"
|
||||
source = "https://factory.talos.dev/image/4a0d65c669d46663f377e7161e50cfd570c401f26fd9e7bda34a0216b6f1922b/v1.11.1/metal-arm64.iso"
|
||||
format = "raw"
|
||||
}
|
||||
|
|
@ -69,37 +69,53 @@ resource "libvirt_volume" "talos_iso" {
|
|||
# Create disk for VM
|
||||
resource "libvirt_volume" "control_plane_disk" {
|
||||
name = "control-plane-node-1-disk.qcow2"
|
||||
pool = "images"
|
||||
pool = "talos-images"
|
||||
base_volume_id = libvirt_volume.talos_iso.id
|
||||
size = 42949672960 # 40GB in bytes
|
||||
format = "qcow2"
|
||||
}
|
||||
|
||||
# Create the VM
|
||||
resource "libvirt_domain" "control_plane_node_1" {
|
||||
name = "control-plane-node-1"
|
||||
memory = 2048
|
||||
vcpu = 2
|
||||
resource "null_resource" "control_plane_node_1" {
|
||||
depends_on = [
|
||||
libvirt_network.talos_bridge,
|
||||
libvirt_volume.control_plane_disk,
|
||||
libvirt_volume.talos_iso
|
||||
]
|
||||
|
||||
disk {
|
||||
volume_id = libvirt_volume.control_plane_disk.id
|
||||
triggers = {
|
||||
cpus = var.vcpu_count,
|
||||
memory = var.memory_mb,
|
||||
cluster_name = var.cluster_name
|
||||
}
|
||||
|
||||
disk {
|
||||
file = libvirt_volume.talos_iso.id
|
||||
provisioner "local-exec" {
|
||||
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 {
|
||||
network_name = "my-talos-net"
|
||||
}
|
||||
provisioner "local-exec" {
|
||||
when = destroyed
|
||||
|
||||
graphics {
|
||||
type = "none"
|
||||
command = <<EOT
|
||||
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