Some checks failed
Run nix flake check / flake-check (push) Has been cancelled
Implement dual improvements to enable efficient testing of pipeline changes without polluting master branch: 1. Add --force flag to create-host script - Skip hostname/IP uniqueness validation - Overwrite existing host configurations - Update entries in flake.nix and terraform/vms.tf (no duplicates) - Useful for iterating on configurations during testing 2. Add branch support to bootstrap mechanism - Bootstrap service reads NIXOS_FLAKE_BRANCH environment variable - Defaults to master if not set - Uses branch in git URL via ?ref= parameter - Service loads environment from /etc/environment 3. Add cloud-init disk support for branch configuration - VMs can specify flake_branch field in terraform/vms.tf - Automatically generates cloud-init snippet setting NIXOS_FLAKE_BRANCH - Uploads snippet to Proxmox via SSH - Production VMs omit flake_branch and use master 4. Update documentation - Document --force flag usage in create-host README - Add branch testing examples in terraform README - Update TODO.md with testing workflow - Add .generated/ to gitignore Testing workflow: Create feature branch, set flake_branch in VM definition, deploy with terraform, iterate with --force flag, clean up before merging. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
56 lines
1.7 KiB
HCL
56 lines
1.7 KiB
HCL
# Cloud-init configuration for branch-specific bootstrap
|
|
#
|
|
# This file manages custom cloud-init snippets for VMs that need to bootstrap
|
|
# from a specific git branch (non-master). Production VMs omit flake_branch
|
|
# and use the default master branch.
|
|
|
|
# Generate cloud-init snippets for VMs with custom branch configuration
|
|
resource "local_file" "cloud_init_branch" {
|
|
for_each = {
|
|
for name, vm in local.vm_configs : name => vm
|
|
if vm.flake_branch != null
|
|
}
|
|
|
|
filename = "${path.module}/.generated/cloud-init-${each.key}.yml"
|
|
content = yamlencode({
|
|
# Write NIXOS_FLAKE_BRANCH to /etc/environment
|
|
# This will be read by bootstrap.nix service via EnvironmentFile
|
|
write_files = [{
|
|
path = "/etc/environment"
|
|
content = "NIXOS_FLAKE_BRANCH=${each.value.flake_branch}\n"
|
|
append = true
|
|
}]
|
|
})
|
|
|
|
file_permission = "0644"
|
|
}
|
|
|
|
# Upload cloud-init snippets to Proxmox
|
|
# Note: This requires SSH access to the Proxmox host
|
|
# Alternative: Manually copy files or use Proxmox API if available
|
|
resource "null_resource" "upload_cloud_init" {
|
|
for_each = {
|
|
for name, vm in local.vm_configs : name => vm
|
|
if vm.flake_branch != null
|
|
}
|
|
|
|
# Trigger re-upload when content changes
|
|
triggers = {
|
|
content_hash = local_file.cloud_init_branch[each.key].content
|
|
}
|
|
|
|
# Upload the cloud-init file to Proxmox snippets directory
|
|
provisioner "local-exec" {
|
|
command = <<-EOT
|
|
scp -o StrictHostKeyChecking=no \
|
|
${local_file.cloud_init_branch[each.key].filename} \
|
|
${var.proxmox_host}:/var/lib/vz/snippets/cloud-init-${each.key}.yml
|
|
EOT
|
|
}
|
|
|
|
depends_on = [local_file.cloud_init_branch]
|
|
}
|
|
|
|
# Ensure VMs depend on cloud-init being uploaded
|
|
# This is handled implicitly by the cicustom reference in vms.tf
|