terraform { # This state is dedicated purely to the physical host configuration. # No providers are required since we use null_resource and ssh. } resource "null_resource" "bare_metal_setup" { triggers = { node = var.node_ip data_disk_id = var.data_disk_id pool_name = var.zfs_pool_name } connection { type = "ssh" user = var.ssh_user host = var.node_ip private_key = var.ssh_private_key != "" ? var.ssh_private_key : null agent = var.ssh_private_key == "" ? true : false } provisioner "remote-exec" { inline = [ "set -euo pipefail", "echo '==> Setting laptop lid switch to ignore (prevents sleeping when closed)...'", "sed -i 's/^#\\?HandleLidSwitch=.*/HandleLidSwitch=ignore/' /etc/systemd/logind.conf", "systemctl restart systemd-logind", "echo '==> Applying NIC offloading fixes...'", "cat <<'EOF' > /etc/systemd/system/nic-offload-fix.service", "[Unit]", "Description=Disable NIC offloading (TSO/GRO/GSO) for physical interfaces", "After=network-online.target", "", "[Service]", "Type=oneshot", "ExecStart=/bin/bash -c 'for dev in /sys/class/net/*; do if [ \"$(basename \"$dev\")\" != \"lo\" ] && [[ ! \"$(basename \"$dev\")\" =~ ^(vmbr|veth|fwbr|tap|bonding) ]]; then /usr/sbin/ethtool -K \"$(basename \"$dev\")\" tso off gso off gro off || true; fi; done'", "RemainAfterExit=yes", "", "[Install]", "WantedBy=multi-user.target", "EOF", "systemctl daemon-reload", "systemctl enable --now nic-offload-fix.service || true", "echo '==> Setting up ZFS pool and Proxmox storage...'", "zpool list ${var.zfs_pool_name} || zpool create -f ${var.zfs_pool_name} /dev/disk/by-id/${var.data_disk_id}", "pvesm status -storage ${var.zfs_pool_name} || pvesm add zfspool ${var.zfs_pool_name} --pool ${var.zfs_pool_name} --content images,rootdir", "echo '==> Host layer configuration complete!'" ] } }