bad things

This commit is contained in:
nora 2024-07-22 22:15:04 +02:00
parent 0b4e5f1e27
commit 0b152a9001
10 changed files with 142 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
/debian-image/build
/tmp
/vm-state
.terraform
terraform.tfstate*

View file

@ -1,3 +1,9 @@
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
packages = with pkgs; [ debootstrap ansible ansible-lint gparted ];
packages = with pkgs; [
ansible
ansible-lint
gparted
opentofu
cdrkit
];
}

2
vm-setup/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/tmp
/state

42
vm-setup/.terraform.lock.hcl generated Normal file
View file

@ -0,0 +1,42 @@
# This file is maintained automatically by "tofu init".
# Manual edits may be lost in future updates.
provider "registry.opentofu.org/dmacvicar/libvirt" {
version = "0.7.6"
constraints = "0.7.6"
hashes = [
"h1:mmbm4vTyC/DCGO4Ed/vbp5AKvy1gmVn/94fzB9VmR08=",
"zh:0bde54f6f658b20b620b875daf106b5b25b1bae4d15408d6c5f06d58360e254d",
"zh:0c97c6930015918b8a34b6d7a2b0c3d17a649c226fcd1874fcba5bbbc0f35972",
"zh:1bdd7aa0011c5f024a09a124836ee9bc8e71b05a6ece810c61824275fd3f695f",
"zh:2b0cc7c794e4caf395d84ffff0b380d17e4b3219a4696264271bfe5059450efe",
"zh:2f8633f7fe07f76c188836ed6f93321ec5fbf5c004bc7699e1741d9b21ed5f37",
"zh:5bf47eed286ce55ed10a5cf657de49a34ab21cc8677c56fef3aab69cdde41a27",
"zh:7dca790fc5fd1d42bc4bc7170be003a7093602026d0f95c8aab84ad551fdf2a4",
"zh:80476b68bc84e3d661d1390025f83879b88f9cdc836de9751af09bd5716089cb",
"zh:82f3e2f3f50176cd6041c8ba36e295cbda1b289ef52ab75b5eceb0f921f64f7b",
"zh:a179b165f3b9bb9a67ebbbf9d73157ded33f02d476b2f58906389dca03b653c9",
"zh:acae54a5d0616f22b3180ddd8e8aad39af664e604394fdacf1f7b337bca2d5b4",
"zh:da4406a2428a9a7e98272c032cb93431c3919253af2fe9934b532d26c0deab09",
"zh:f63dbd8e579ab5268d01ffab4503b8a8e736b70d1a04e4f271559ba8dd133dcd",
"zh:f85c1d9e51a94ecde137435c9d6b0fb7be590437ea8a725334d1577eebbc550c",
]
}
provider "registry.opentofu.org/hashicorp/local" {
version = "2.5.1"
constraints = "2.5.1"
hashes = [
"h1:GgW5qncKu4KnXLE1ZYv5iwmhSYtTNzsOvJAOQIyFR7E=",
"zh:031c2c2070672b7e78e0aa15560839278dc57fe7cf1e58a617ac13c67b31d5fb",
"zh:1ef64ea4f8382cd538a76f3d319f405d18130dc3280f1c16d6aaa52a188ecaa4",
"zh:422ce45691b2f384dbd4596fdc8209d95cb43d85a82aaa0173089d38976d6e96",
"zh:7415fbd8da72d9363ba55dd8115837714f9534f5a9a518ec42268c2da1b9ed2f",
"zh:92aa22d071339c8ef595f18a9f9245c287266c80689f5746b26e10eaed04d542",
"zh:9cd0d99f5d3be835d6336c19c4057af6274e193e677ecf6370e5b0de12b4aafe",
"zh:a8c1525b389be5809a97f02aa7126e491ba518f97f57ed3095a3992f2134bb8f",
"zh:b336fa75f72643154b07c09b3968e417a41293358a54fe03efc0db715c5451e6",
"zh:c66529133599a419123ad2e42874afbd9aba82bd1de2b15cc68d2a1e665d4c8e",
"zh:c7568f75ba6cb7c3660b69eaab8b0e4278533bd9a7a4c33ee6590cc7e69743ea",
]
}

3
vm-setup/main.tf Normal file
View file

@ -0,0 +1,3 @@
locals {
vm_count = 1
}

6
vm-setup/net.tf Normal file
View file

@ -0,0 +1,6 @@
resource "libvirt_network" "lab" {
name = "lab"
mode = "nat"
domain = "lab.local"
addresses = ["10.0.0.0/8"]
}

22
vm-setup/setup.sh Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -eu
IMG_DOWNLOADED=debian-12-generic-amd64.qcow2
IMG=debian-12-generic-amd64-bigger.qcow2
mkdir -p tmp
mkdir -p state
if ! [ -f "tmp/$IMG_DOWNLOADED" ]; then
curl -L -o "tmp/$IMG_DOWNLOADED" https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2
fi
if ! [ -f "tmp/$IMG" ]; then
cp "tmp/$IMG_DOWNLOADED" "tmp/$IMG"
sudo qemu-img resize tmp/$IMG 30G
sudo modprobe nbd max_part=10
sudo qemu-nbd -c /dev/nbd0 tmp/$IMG
sudo gparted /dev/nbd0
sudo qemu-nbd -d /dev/nbd0
fi

16
vm-setup/versions.tf Normal file
View file

@ -0,0 +1,16 @@
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
version = "0.7.6"
}
local = {
source = "hashicorp/local"
version = "2.5.1"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}

42
vm-setup/vm.tf Normal file
View file

@ -0,0 +1,42 @@
locals {
cloudinit_user_data = file("${path.module}/user-data")
}
resource "libvirt_cloudinit_disk" "user_data" {
name = "commoninit.iso"
user_data = local.cloudinit_user_data
}
resource "local_file" "debian-node-disk" {
count = local.vm_count
content = ""
filename = "${path.module}/state/debian-node-${count.index}.qcow2.stamp"
provisioner "local-exec" {
command = <<EOT
cp "${path.module}/tmp/debian-12-generic-amd64-bigger.qcow2" "${path.module}/state/debian-node-${count.index}.qcow2"
chmod 777 "${path.module}/state/debian-node-${count.index}.qcow2"
EOT
}
}
resource "libvirt_domain" "debian-node" {
count = local.vm_count
name = "debian-node-${count.index}"
memory = "2048"
vcpu = 2
cloudinit = libvirt_cloudinit_disk.user_data.id
network_interface {
network_id = libvirt_network.lab.id
hostname = "debian-node-${count.index}"
addresses = ["10.0.1.${count.index+1}"]
}
disk {
file = "${abspath(path.module)}/state/debian-node-${count.index}.qcow2"
}
}