diff --git a/cloud-init/user-data-alpine.yml.tftpl b/cloud-init/user-data-alpine.yml.tftpl new file mode 100644 index 0000000..1148f5e --- /dev/null +++ b/cloud-init/user-data-alpine.yml.tftpl @@ -0,0 +1,52 @@ +#cloud-config + +# 1. Hostname configuration +hostname: ${hostname} +fqdn: ${hostname} +preserve_hostname: false + +# 2. User creation +# On Alpine, the privilege escalation group is "wheel" (not "sudo"). +# Keep the default shell (ash/busybox) to stay lightweight. +users: + - name: ${username} + sudo: ALL=(ALL) NOPASSWD:ALL + groups: wheel + ssh_authorized_keys: + - ${ssh_key} + +# 3. apk repositories configuration +# Pin the two repositories used on this homelab: edge/main + edge/community. +# Written BEFORE package_update/package_upgrade so apk uses this config immediately. +write_files: + - path: /etc/apk/repositories + owner: root:root + permissions: '0644' + content: | + http://dl-cdn.alpinelinux.org/alpine/edge/main + http://dl-cdn.alpinelinux.org/alpine/edge/community + +# 4. System update (apk) +package_update: true +package_upgrade: true + +# 5. Package installation +# - qemu-guest-agent: main repo (required so Proxmox/Terraform can read the VM IP) +# - tailscale: community repo +packages: + - qemu-guest-agent + - curl + - sudo + - tailscale + +# 6. Services & configuration (OpenRC, not systemd) +# Intentional order: qemu-guest-agent first to unblock Terraform as soon as possible. +runcmd: + # Enable and start qemu-guest-agent via OpenRC + - [ rc-update, add, qemu-guest-agent, default ] + - [ rc-service, qemu-guest-agent, start ] + # Enable and start Tailscale via OpenRC + - [ rc-update, add, tailscale, default ] + - [ rc-service, tailscale, start ] + # Register the node with the tailnet + - [ tailscale, up, --authkey=${tailscale_auth_key}, --hostname=${vm_name} ] diff --git a/cloud-init/user-data-systemd.yml.tftpl b/cloud-init/user-data-systemd.yml.tftpl new file mode 100644 index 0000000..1d1ab1b --- /dev/null +++ b/cloud-init/user-data-systemd.yml.tftpl @@ -0,0 +1,32 @@ +#cloud-config + +# 1. Hostname configuration +hostname: ${hostname} +fqdn: ${hostname} +preserve_hostname: false + +# 2. User creation +users: + - name: ${username} + sudo: ALL=(ALL) NOPASSWD:ALL + groups: sudo, admin + shell: /bin/bash + ssh_authorized_keys: + - ${ssh_key} + +# 3. System update +package_update: true +package_upgrade: true + +# 4. Package installation +packages: + - qemu-guest-agent + - curl + +# 5. Tailscale installation and configuration +runcmd: + # Enable and start qemu-guest-agent (systemd) + - [ systemctl, enable, qemu-guest-agent, --now ] + # Install and configure Tailscale + - [ sh, -c, "curl -fsSL https://tailscale.com/install.sh | sh" ] + - [ tailscale, up, --authkey=${tailscale_auth_key}, --hostname=${vm_name} ]