From 55db013dfbb4864420816e53c3bd52039a893ba0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Aveni" Date: Tue, 30 Jun 2026 07:18:55 -0700 Subject: [PATCH] Increase AMI builder capacity --- main.tf | 16 +++++++++++----- variables.tf | 28 ++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 9a305fa..ec695bf 100644 --- a/main.tf +++ b/main.tf @@ -46,10 +46,11 @@ locals { ? "nixos/*-${var.system}" : var.base_nixos_ami_name_pattern ) - base_nixos_ami_id = var.base_nixos_ami_id == null ? data.aws_ami.nixos[0].id : var.base_nixos_ami_id - resource_name = "${var.name}-builder-${local.aws_architecture}-${substr(var.input_hash, 0, 12)}" - nix_device_id = replace(aws_ebs_volume.nix.id, "-", "") - nix_device = "/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_${local.nix_device_id}" + builder_instance_type = var.builder_instance_type == null ? (var.system == "aarch64-linux" ? "c7g.2xlarge" : "c7i.2xlarge") : var.builder_instance_type + base_nixos_ami_id = var.base_nixos_ami_id == null ? data.aws_ami.nixos[0].id : var.base_nixos_ami_id + resource_name = "${var.name}-builder-${local.aws_architecture}-${substr(var.input_hash, 0, 12)}" + nix_device_id = replace(aws_ebs_volume.nix.id, "-", "") + nix_device = "/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_${local.nix_device_id}" tags = { Name = local.resource_name Project = var.name @@ -114,6 +115,8 @@ resource "aws_ebs_volume" "nix" { availability_zone = data.aws_subnet.selected.availability_zone size = var.nix_volume_size_gb type = "gp3" + iops = var.nix_volume_iops + throughput = var.nix_volume_throughput tags = merge(local.tags, { Name = "${local.resource_name}-nix" @@ -122,11 +125,12 @@ resource "aws_ebs_volume" "nix" { resource "aws_instance" "builder" { ami = local.base_nixos_ami_id - instance_type = var.builder_instance_type + instance_type = local.builder_instance_type subnet_id = local.subnet_id vpc_security_group_ids = [aws_security_group.builder.id] iam_instance_profile = aws_iam_instance_profile.builder.name associate_public_ip_address = true + ebs_optimized = true key_name = var.ssh_public_key == null ? null : aws_key_pair.admin[0].key_name user_data_replace_on_change = true @@ -143,6 +147,8 @@ resource "aws_instance" "builder" { root_block_device { volume_size = var.root_volume_size_gb volume_type = "gp3" + iops = var.root_volume_iops + throughput = var.root_volume_throughput } tags = local.tags diff --git a/variables.tf b/variables.tf index 36cfae8..b45fddb 100644 --- a/variables.tf +++ b/variables.tf @@ -38,8 +38,8 @@ variable "flake_lock_rev" { variable "builder_instance_type" { type = string - default = "t4g.large" - description = "Temporary EC2 instance type used to build and seed the AMI." + default = null + description = "Temporary EC2 instance type used to build and seed the AMI. Defaults to c7g.2xlarge for aarch64-linux and c7i.2xlarge for x86_64-linux." } variable "vpc_id" { @@ -78,12 +78,36 @@ variable "root_volume_size_gb" { description = "Temporary builder root EBS volume size. This becomes the final AMI root snapshot size." } +variable "root_volume_iops" { + type = number + default = 6000 + description = "Temporary builder root gp3 IOPS. This affects builder speed only; snapshots do not preserve provisioned IOPS." +} + +variable "root_volume_throughput" { + type = number + default = 250 + description = "Temporary builder root gp3 throughput in MiB/s. This affects builder speed only; snapshots do not preserve provisioned throughput." +} + variable "nix_volume_size_gb" { type = number default = 50 description = "Temporary /nix EBS volume size. This becomes the final AMI /nix snapshot size." } +variable "nix_volume_iops" { + type = number + default = 12000 + description = "Temporary /nix gp3 IOPS used while building and seeding the AMI." +} + +variable "nix_volume_throughput" { + type = number + default = 500 + description = "Temporary /nix gp3 throughput in MiB/s used while building and seeding the AMI." +} + variable "nix_pool" { type = string default = "nixos-zfs-nix"