Compare commits

...

15 commits

Author SHA1 Message Date
ab4edac3e2
limit disk size
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 20:01:49 +02:00
d30f823cc4
clean some comments
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 19:28:35 +02:00
6bf161e123
clean out comments
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 18:40:59 +02:00
f20dca45f8
use insecure for test only
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 18:34:26 +02:00
f24620f500
dedupe block
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 18:34:09 +02:00
8b87b997ef
lower memory
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 18:26:37 +02:00
bbbe3c6770
rename bridge
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:54:33 +02:00
1fd2c5a397
fix tf syntax
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:35:48 +02:00
a6ebb3986f
pass ipv6
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:33:18 +02:00
ab0dadeb45
add no-op second invocation
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:33:08 +02:00
b5e09cfe94
rm apparently unnecessary gateway stuff
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:32:32 +02:00
0b1bad3f87
trigger update by codebase hash
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:28:57 +02:00
c2be91881d
add fixmes
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:28:03 +02:00
7c72f783a8
rm memory size
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:27:30 +02:00
8ae2c665bf
output id
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-20 17:08:45 +02:00
2 changed files with 35 additions and 57 deletions

View file

@ -24,7 +24,7 @@ let
];
key-file = "/root/.ssh/id_ed25519";
node-name = "pve";
bridge = "br-vm";
bridge = "br0";
vlanId = 0;
imageDatastoreId = "local";
vmDatastoreId = "local";
@ -73,33 +73,20 @@ in
networking.useDHCP = false;
networking = {
bridges.br-vm.interfaces = [ ]; # internal bridge
interfaces.br-vm.ipv4.addresses = [
bridges.br0.interfaces = [ ];
interfaces.br0.ipv4.addresses = [
{
address = "192.168.10.1";
prefixLength = 24;
}
];
# Timed out waiting for device /sys/subsystem/net/devices/br0
interfaces.br0.ipv4.addresses = [
{
address = "192.168.1.3";
prefixLength = 24;
}
];
nat = {
enable = true;
# Timed out waiting for device /sys/subsystem/net/devices/br0
externalInterface = "br0";
internalInterfaces = [ "br-vm" ];
internalInterfaces = [ "br0" ];
};
};
boot.kernel.sysctl."net.ipv4.ip_forward" = "1";
networking.defaultGateway = {
interface = "br0";
address = "192.168.1.1";
};
users.users.root = {
password = "mytestpw";
hashedPasswordFile = lib.mkForce null;
@ -110,8 +97,8 @@ in
ipAddress = "192.168.1.1";
};
virtualisation = {
diskSize = 24 * 1024;
memorySize = 4 * 1024;
diskSize = 5 * 1024;
memorySize = 3 * 1024;
};
};
@ -162,9 +149,6 @@ in
KMS_KEY = "tsjxw9NjKUBUlzbTnD7orqIAdEmpGYRARvxD51jtY+o=";
};
};
virtualisation = {
memorySize = lib.mkForce (24 * 1024);
};
};
extraTestScript = ''
@ -219,18 +203,23 @@ in
openssl verify -CApath /etc/ssl/certs ./pve-root-ca.pem
""")
deploy = f"""
ssh -o BatchMode=yes -o StrictHostKeyChecking=no pve "true"
export PROXMOX_VE_INSECURE="true"
export SSL_CERT_FILE=/tmp/pve-ca-bundle.crt
export PROXMOX_VE_API_TOKEN="root@pam!mytoken={pm_token}"
${lib.getExe deployment.run} | jq -r '.ipv4.value[0]'
"""
with subtest("Run the deployment"):
ip = deployer.succeed(deploy).strip()
ip = deployer.succeed(f"""
export SSL_CERT_FILE=/tmp/pve-ca-bundle.crt
ssh -o BatchMode=yes -o StrictHostKeyChecking=no pve "true"
export PROXMOX_VE_API_TOKEN="root@pam!mytoken={pm_token}"
${lib.getExe deployment.run} | jq -r '.ipv4.value[0]'
# ${lib.getExe deployment.run} >&2
""").strip()
with subtest("Verify package"):
deployer.succeed(f"""
ssh -i "/root/.ssh/id_ed25519" -o StrictHostKeyChecking=no -o BatchMode=yes -J pve root@{ip} su - operator -c hello >&2
""")
with subtest("No-op update"):
deployer.succeed(deploy, timeout=120)
'';
}

View file

@ -16,9 +16,6 @@ locals {
# https://registry.terraform.io/providers/bpg/proxmox/latest/docs
provider "proxmox" {
endpoint = "https://${var.host}:8006/"
insecure = true
# FIXME secure
# insecure = false
# used only for files and creating custom disks
ssh {
@ -33,12 +30,13 @@ provider "proxmox" {
}
}
# # hash of our code directory, used to trigger re-deploy
# # FIXME calculate separately to reduce false positives
# data "external" "hash" {
# program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ..)\\\"}\""]
# }
# hash of our code directory, used to trigger re-deploy
# FIXME calculate separately to reduce false positives
data "external" "hash" {
program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ../../..)\\\"}\""]
}
# FIXME (un)stream
# FIXME handle known-hosts in TF state
# FIXME move to host
# FIXME switch to base image shared between jobs as upload seems a bottleneck? e.g. by:
@ -51,13 +49,6 @@ resource "proxmox_virtual_environment_file" "upload" {
# create = "60m"
# }
# content_type - (Optional) The content type. If not specified, the content type will be inferred from the file extension. Valid values are:
# backup (allowed extensions: .vzdump, .tar.gz, .tar.xz, tar.zst)
# iso (allowed extensions: .iso, .img)
# snippets (allowed extensions: any)
# import (allowed extensions: .raw, .qcow2, .vmdk)
# vztmpl (allowed extensions: .tar.gz, .tar.xz, tar.zst)
# content_type = "backup"
content_type = "import"
# https://192.168.51.81:8006/#v1:0:=storage%2Fnode051%2Flocal:4::=contentIso:::::
# PVE -> Datacenter -> Storage -> local -> Edit -> General -> Content -> check Import + Disk Images -> OK
@ -83,6 +74,7 @@ resource "proxmox_virtual_environment_vm" "nix_vm" {
# or just defer syncing when only this changed?
ignore_changes = [
disk["import_from"],
initialization,
]
}
node_name = var.node_name
@ -118,11 +110,6 @@ resource "proxmox_virtual_environment_vm" "nix_vm" {
ssd = true
backup = false
cache = "none"
# FIXME make the provider allow this as a distinct block to allow making this depend on VM id?
# FIXME replace with an effectful ~~function~~template from vm_id replacing resource `proxmox_virtual_environment_file.upload`
# import_from = "local:import/${proxmox_virtual_environment_vm.nix_vm.vm_id}-${local.dump_name}" # bogus import name to test if it would accept self-referential values here # may not refer to itself
# import_from = "local:import/${local.dump_name}"
import_from = proxmox_virtual_environment_file.upload.id
}
@ -153,10 +140,10 @@ resource "proxmox_virtual_environment_vm" "nix_vm" {
gateway = var.ipv4_gateway
address = var.ipv4_address
}
# ipv6 {
# gateway = var.ipv6_gateway
# address = var.ipv6_address
# }
ipv6 {
gateway = var.ipv6_gateway
address = var.ipv6_address
}
}
}
}
@ -170,20 +157,22 @@ resource "null_resource" "await_ssh" {
}
}
# FIXME expose (and handle thru) [`exec`](https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/agent/exec) endpoint in proxmox TF provider? wait, what command would i use it for?: https://github.com/bpg/terraform-provider-proxmox/issues/1576
module "nixos-rebuild" {
depends_on = [
null_resource.await_ssh
data.external.hash,
null_resource.await_ssh,
]
source = "../tf-single-host"
nixos_conf = var.nixos_conf
# username = var.ssh_user # refers to the proxmox ssh user, not the VM one
username = "root"
host = proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[1][0]
key_file = var.key_file
ssh_opts = var.ssh_opts
}
output "id" {
value = proxmox_virtual_environment_vm.nix_vm.vm_id
}
output "ipv4" {
value = proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[1]
}