Add NixOS ZFS EC2 AMI builder

This commit is contained in:
Timothy J. Aveni
2026-06-20 11:28:38 -07:00
commit b2e4b7fcaa
9 changed files with 681 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
locals {
resource_name = "${var.name}-${var.architecture}-${substr(var.input_hash, 0, 12)}"
tags = {
Name = local.resource_name
Project = var.name
Architecture = var.architecture
InputHash = var.input_hash
BuilderGitRev = var.builder_git_rev
FlakeLockRev = var.flake_lock_rev
RootSnapshotId = var.root_snapshot_id
NixSnapshotId = var.nix_snapshot_id
NixosSystemClosure = var.nixos_system_closure
}
}
resource "aws_ami" "matched" {
name = local.resource_name
description = "NixOS EC2 AMI with matched root and ZFS /nix snapshots"
architecture = var.architecture
virtualization_type = "hvm"
root_device_name = var.root_device_name
ena_support = true
ebs_block_device {
device_name = var.root_device_name
snapshot_id = var.root_snapshot_id
volume_size = var.root_volume_size_gb
volume_type = "gp3"
delete_on_termination = true
}
ebs_block_device {
device_name = var.nix_device_name
snapshot_id = var.nix_snapshot_id
volume_size = var.nix_volume_size_gb
volume_type = "gp3"
delete_on_termination = true
}
tags = local.tags
lifecycle {
prevent_destroy = true
}
}