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 } }