vortex
Home & Overview Capabilities Live Workbench Pricing & 3x Guarantee Security & IAM Open-Source Guardrails Kit Interactive Reference Deliverable Book 15-Min Live Teardown
Open-Source Engineering Proof · MIT License · Terraform & OPA Validated

Open-Source FinOps Guardrails Kit.

Audit our production Infrastructure-as-Code quality in 60 seconds before speaking with us. Four copy-ready Terraform, Karpenter v1, OPA/Conftest, and GitHub Actions ARM64 Spot modules eliminating the highest-leverage AWS, EKS & CI/CD cost leaks with zero runtime agents and zero vendor lock-in.

✓ terraform validate PASSED karpenter.sh/v1 + rego.v1 MIT License Zero Runtime Agents

4 Production Modules Ready for Your GitOps Pipeline

Every Cloud Cost Surgery Sprint ships clean, reversible pull requests inside your own repositories—never proprietary SaaS dashboards or cluster sidecars. Copy any module below directly into your Terraform or Kubernetes repo.

Zero-Credential Local Verification
Run inside either Terraform module directory (zero AWS credentials):
terraform fmt -check -recursive && terraform init -backend=false && terraform validate
Module 01 · Terraform AWS >= 5.0 · MIT License

AWS NAT Gateway & VPC Endpoints Guard

open-source-kit/aws-nat-gateway-endpoints-guard/

Eliminates $0.045–$0.059/GB Managed NAT Gateway processing charges on S3, DynamoDB, and ECR container image pulls by binding zero-cost Gateway Endpoints to every private route table and adding bounded VPC Flow Logs (14-day default TTL) to surface residual top talkers.

Zero Downtime · $0/GB S3 + DynamoDB Gateway Endpoints + Optional ECR PrivateLink + Bounded Flow Logs
aws-nat-gateway-endpoints-guard/main.tf 153 lines · HCL / Terraform
data "aws_vpc" "selected" {
  count = var.enable_ecr_interface_endpoints && var.vpc_cidr_block == null ? 1 : 0
  id    = var.vpc_id
}

locals {
  resolved_vpc_cidr = var.enable_ecr_interface_endpoints ? (
    var.vpc_cidr_block != null ? var.vpc_cidr_block : data.aws_vpc.selected[0].cidr_block
  ) : null
  common_tags = merge(
    {
      ManagedBy = "Terraform"
      Module    = "vortex-aws-nat-gateway-endpoints-guard"
    },
    var.tags
  )
}

# 1. Zero-Cost ($0/GB) S3 Gateway VPC Endpoint across ALL private route tables
resource "aws_vpc_endpoint" "s3_gateway" {
  vpc_id            = var.vpc_id
  service_name      = "com.amazonaws.${var.region}.s3"
  vpc_endpoint_type = "Gateway"
  route_table_ids   = var.private_route_table_ids

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-s3-gateway-endpoint"
  })
}

# 2. Zero-Cost ($0/GB) DynamoDB Gateway VPC Endpoint
resource "aws_vpc_endpoint" "dynamodb_gateway" {
  count = var.enable_dynamodb_endpoint ? 1 : 0

  vpc_id            = var.vpc_id
  service_name      = "com.amazonaws.${var.region}.dynamodb"
  vpc_endpoint_type = "Gateway"
  route_table_ids   = var.private_route_table_ids

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-dynamodb-gateway-endpoint"
  })
}

# 3. Optional ECR Interface Endpoints (eliminates NAT Gateway tax on EKS container pulls)
resource "aws_security_group" "ecr_endpoints" {
  count = var.enable_ecr_interface_endpoints ? 1 : 0

  name        = "${var.name_prefix}-ecr-endpoints-sg"
  description = "Allow HTTPS from private VPC CIDR to ECR PrivateLink Interface Endpoints"
  vpc_id      = var.vpc_id

  ingress {
    description = "HTTPS from VPC CIDR"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = [local.resolved_vpc_cidr]
  }

  egress {
    description = "Allow outbound responses"
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-ecr-endpoints-sg"
  })
}

resource "aws_vpc_endpoint" "ecr_api" {
  count = var.enable_ecr_interface_endpoints ? 1 : 0

  vpc_id              = var.vpc_id
  service_name        = "com.amazonaws.${var.region}.ecr.api"
  vpc_endpoint_type   = "Interface"
  subnet_ids          = var.private_subnet_ids
  security_group_ids  = [aws_security_group.ecr_endpoints[0].id]
  private_dns_enabled = true

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-ecr-api-endpoint"
  })

  lifecycle {
    precondition {
      condition     = length(var.private_subnet_ids) > 0
      error_message = "private_subnet_ids must contain at least one private subnet ID when enable_ecr_interface_endpoints is true."
    }
  }
}

resource "aws_vpc_endpoint" "ecr_dkr" {
  count = var.enable_ecr_interface_endpoints ? 1 : 0

  vpc_id              = var.vpc_id
  service_name        = "com.amazonaws.${var.region}.ecr.dkr"
  vpc_endpoint_type   = "Interface"
  subnet_ids          = var.private_subnet_ids
  security_group_ids  = [aws_security_group.ecr_endpoints[0].id]
  private_dns_enabled = true

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-ecr-dkr-endpoint"
  })
}

# 4. Bounded VPC Flow Logs to diagnose residual NAT Gateway & Cross-AZ data transfer
resource "aws_cloudwatch_log_group" "nat_flow_logs" {
  count = var.enable_nat_flow_logs ? 1 : 0

  name              = "/aws/vpc/flow-logs/${var.name_prefix}"
  retention_in_days = var.flow_log_retention_days
  tags              = local.common_tags
}

resource "aws_iam_role" "flow_logs_role" {
  count = var.enable_nat_flow_logs ? 1 : 0

  name = "${var.name_prefix}-vpc-flow-logs-role"
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect    = "Allow"
      Principal = { Service = "vpc-flow-logs.amazonaws.com" }
      Action    = "sts:AssumeRole"
    }]
  })
  tags = local.common_tags
}

resource "aws_iam_role_policy" "flow_logs_policy" {
  count = var.enable_nat_flow_logs ? 1 : 0

  name = "${var.name_prefix}-vpc-flow-logs-write"
  role = aws_iam_role.flow_logs_role[0].id
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect = "Allow"
      Action = [
        "logs:CreateLogStream",
        "logs:PutLogEvents",
        "logs:DescribeLogGroups",
        "logs:DescribeLogStreams"
      ]
      Resource = "${aws_cloudwatch_log_group.nat_flow_logs[0].arn}:*"
    }]
  })
}

resource "aws_flow_log" "nat_audit" {
  count = var.enable_nat_flow_logs ? 1 : 0

  vpc_id                   = var.vpc_id
  traffic_type             = "ACCEPT"
  log_destination_type     = "cloud-watch-logs"
  log_destination          = aws_cloudwatch_log_group.nat_flow_logs[0].arn
  iam_role_arn             = aws_iam_role.flow_logs_role[0].arn
  max_aggregation_interval = 600

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-nat-audit-flow-log"
  })
}
aws-nat-gateway-endpoints-guard/variables.tf 72 lines · Input Validation Guards
variable "vpc_id" {
  type        = string
  description = "Target AWS VPC ID where private workloads run."
}

variable "region" {
  type        = string
  description = "AWS region (e.g., us-east-1, eu-central-2, eu-west-2)."
}

variable "private_route_table_ids" {
  type        = list(string)
  description = "ALL private subnet route table IDs across every Availability Zone. Omitting even one AZ route table causes silent NAT Gateway bleed."

  validation {
    condition     = length(var.private_route_table_ids) > 0
    error_message = "At least one private route table ID must be provided."
  }
}

variable "enable_dynamodb_endpoint" {
  type        = bool
  description = "Deploy a zero-cost ($0/GB) DynamoDB Gateway VPC Endpoint."
  default     = true
}

variable "enable_ecr_interface_endpoints" {
  type        = bool
  description = "Deploy PrivateLink Interface Endpoints for ecr.api and ecr.dkr to keep container image pulls off Managed NAT Gateways."
  default     = false
}

variable "private_subnet_ids" {
  type        = list(string)
  description = "Private subnet IDs (one per AZ) required when enable_ecr_interface_endpoints is true."
  default     = []
}

variable "vpc_cidr_block" {
  type        = string
  description = "Optional explicit VPC CIDR block permitted to reach ECR Interface Endpoints on TCP 443. When null, resolved dynamically from data.aws_vpc.selected."
  default     = null

  validation {
    condition     = var.vpc_cidr_block == null || can(cidrhost(var.vpc_cidr_block, 0))
    error_message = "vpc_cidr_block must be a valid IPv4 CIDR block (e.g., 10.20.0.0/16) or null."
  }
}

variable "enable_nat_flow_logs" {
  type        = bool
  description = "Enable VPC Flow Logs to CloudWatch with bounded retention to audit residual NAT Gateway and Cross-AZ data transfer."
  default     = true
}

variable "flow_log_retention_days" {
  type        = number
  description = "CloudWatch Logs retention in days for VPC Flow Logs (bounded to prevent log storage drift)."
  default     = 14

  validation {
    condition     = contains([1, 3, 5, 7, 14, 30, 60, 90], var.flow_log_retention_days)
    error_message = "flow_log_retention_days must be a bounded AWS CloudWatch retention value (1 to 90 days)."
  }
}

variable "name_prefix" {
  type        = string
  description = "Prefix applied to security groups, IAM roles, and log groups."
  default     = "vortex-nat-guard"
}

variable "tags" {
  type        = map(string)
  description = "Additional tags applied to all created resources."
  default     = {}
}
aws-nat-gateway-endpoints-guard/outputs.tf 22 lines · Outputs
output "s3_gateway_endpoint_id" {
  value       = aws_vpc_endpoint.s3_gateway.id
  description = "ID of the zero-cost S3 Gateway VPC Endpoint."
}

output "dynamodb_gateway_endpoint_id" {
  value       = try(aws_vpc_endpoint.dynamodb_gateway[0].id, null)
  description = "ID of the zero-cost DynamoDB Gateway VPC Endpoint (if enabled)."
}

output "ecr_interface_endpoint_ids" {
  value = var.enable_ecr_interface_endpoints ? {
    ecr_api = aws_vpc_endpoint.ecr_api[0].id
    ecr_dkr = aws_vpc_endpoint.ecr_dkr[0].id
  } : {}
  description = "Map of ECR PrivateLink Interface Endpoint IDs (if enabled)."
}

output "flow_log_group_name" {
  value       = try(aws_cloudwatch_log_group.nat_flow_logs[0].name, null)
  description = "CloudWatch Log Group name capturing bounded VPC Flow Logs for NAT/Cross-AZ diagnostics."
}
aws-nat-gateway-endpoints-guard/versions.tf 10 lines · Provider Constraints
terraform {
  required_version = ">= 1.5.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.0"
    }
  }
}
Example Module Invocation (Terraform) HCL Usage
module "nat_gateway_guard" {
  source = "./aws-nat-gateway-endpoints-guard"

  vpc_id                  = aws_vpc.prod.id
  region                  = "eu-central-2"
  private_route_table_ids = aws_route_table.private[*].id

  enable_dynamodb_endpoint       = true
  enable_ecr_interface_endpoints = true
  private_subnet_ids             = aws_subnet.private[*].id
  vpc_cidr_block                 = aws_vpc.prod.cidr_block
  enable_nat_flow_logs           = true
  flow_log_retention_days        = 14
}
Module 02 · karpenter.sh/v1 + OPA Rego v1 · MIT License

Karpenter Consolidation & PDB Deadlock Guard

open-source-kit/karpenter-consolidation-pdb-guard/

Unblocks EKS Karpenter WhenEmptyOrUnderutilized consolidation and enforces a CI policy via OPA/Conftest so engineers cannot re-introduce rigid PodDisruptionBudget manifests (minAvailable: "100%" or maxUnavailable: 0) or omit zone-local trafficDistribution: PreferClose.

EKS Bin-Packing + CI Gate Graviton arm64 + amd64 · Spot/On-Demand · 10% Disruption Budget
karpenter-consolidation-pdb-guard/karpenter-nodepool.yaml 62 lines · Kubernetes / Karpenter v1
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: vortex-stateless-consolidated
spec:
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 30s
    budgets:
      - nodes: "10%"
  limits:
    cpu: "256"
    memory: "512Gi"
  template:
    metadata:
      labels:
        workload-tier: stateless
        managed-by: karpenter-finops-guard
    spec:
      expireAfter: 720h
      nodeClassRef:
        group: karpenter.k8s.aws
        kind: EC2NodeClass
        name: default-gp3-nodeclass
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot", "on-demand"]
        - key: kubernetes.io/arch
          operator: In
          values: ["arm64", "amd64"]
        - key: karpenter.k8s.aws/instance-category
          operator: In
          values: ["c", "m", "r"]
        - key: karpenter.k8s.aws/instance-generation
          operator: Gt
          values: ["5"]
---
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata:
  name: default-gp3-nodeclass
spec:
  # Karpenter v1: alias in amiSelectorTerms infers AL2023 automatically (do NOT pair with amiFamily)
  amiSelectorTerms:
    - alias: al2023@latest
  role: "KarpenterNodeRole-REPLACE_WITH_CLUSTER_NAME"
  subnetSelectorTerms:
    - tags:
        karpenter.sh/discovery: "REPLACE_WITH_CLUSTER_NAME"
  securityGroupSelectorTerms:
    - tags:
        karpenter.sh/discovery: "REPLACE_WITH_CLUSTER_NAME"
  blockDeviceMappings:
    - deviceName: /dev/xvda
      ebs:
        volumeSize: 50Gi
        volumeType: gp3
        iops: 3000
        throughput: 125
        encrypted: true
        deleteOnTermination: true
karpenter-consolidation-pdb-guard/policy/pdb_consolidation_guard.rego 45 lines · OPA / Conftest Rego v1
package main

import rego.v1

# Vortex Cloud & FinOps — OPA/Conftest CI Policy
# Prevents PodDisruptionBudget deadlocks that block Karpenter node consolidation
# and flags multi-AZ Services missing zone-local traffic routing.

deny contains msg if {
	input.kind == "PodDisruptionBudget"
	input.spec.minAvailable == "100%"
	msg := sprintf(
		"PodDisruptionBudget '%s' sets minAvailable: 100%% (ALLOWED DISRUPTIONS: 0), permanently blocking Karpenter node consolidation. Use maxUnavailable: 1 for stateless workloads.",
		[input.metadata.name],
	)
}

deny contains msg if {
	input.kind == "PodDisruptionBudget"
	input.spec.maxUnavailable == 0
	msg := sprintf(
		"PodDisruptionBudget '%s' sets maxUnavailable: 0, blocking Karpenter node drain and consolidation. Set maxUnavailable: 1 or minAvailable < 100%%.",
		[input.metadata.name],
	)
}

deny contains msg if {
	input.kind == "PodDisruptionBudget"
	input.spec.maxUnavailable == "0%"
	msg := sprintf(
		"PodDisruptionBudget '%s' sets maxUnavailable: 0%%, blocking Karpenter node drain. Set maxUnavailable: 1 or a percentage > 0%%.",
		[input.metadata.name],
	)
}

warn contains msg if {
	input.kind == "Service"
	object.get(input.spec, "type", "ClusterIP") == "ClusterIP"
	not object.get(input.spec, "trafficDistribution", "") in {"PreferSameZone", "PreferClose"}
	not input.metadata.annotations["service.kubernetes.io/topology-mode"]
	msg := sprintf(
		"ClusterIP Service '%s' omits trafficDistribution: PreferSameZone (K8s 1.33+; PreferClose on 1.31–1.32), which can generate unnecessary $0.02/GB Cross-AZ data transfer.",
		[input.metadata.name],
	)
}
karpenter-consolidation-pdb-guard/examples/good-pdb.yaml 10 lines · Passes Conftest Policy
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: checkout-worker-pdb
  namespace: production
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: checkout-worker
karpenter-consolidation-pdb-guard/examples/bad-pdb.yaml 10 lines · Blocked in CI by Conftest
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: legacy-checkout-worker-pdb
  namespace: production
spec:
  minAvailable: "100%"
  selector:
    matchLabels:
      app: checkout-worker
Conftest / GitHub Actions Verification Bash
# Run against your Kubernetes manifests in CI (fails build on PDB deadlocks)
conftest test ./k8s-manifests/ -p ./karpenter-consolidation-pdb-guard/policy

# Quick self-test with bundled fixtures:
conftest test karpenter-consolidation-pdb-guard/examples/good-pdb.yaml -p karpenter-consolidation-pdb-guard/policy
conftest test karpenter-consolidation-pdb-guard/examples/bad-pdb.yaml  -p karpenter-consolidation-pdb-guard/policy
Module 03 · Terraform AWS >= 5.0 · MIT License

AWS Storage, EBS gp3, DLM Snapshot & CloudWatch TTL Guard

open-source-kit/aws-storage-cloudwatch-ttl-guard/

Stops three quiet storage and observability leaks at terraform plan time: blocks legacy gp2 EBS volumes (enforcing gp3 at -20% base cost + 3,000 baseline IOPS), caps CloudWatch Log Group retention at bounded enums (14–30d instead of Never Expire), and automates daily EBS snapshot expiration via AWS Data Lifecycle Manager (DLM).

Plan-Time Policy Guard gp2 Blocked · Bounded Log TTL · Automated DLM Snapshot Expiry
aws-storage-cloudwatch-ttl-guard/main.tf 111 lines · HCL / Terraform
locals {
  common_tags = merge(
    {
      ManagedBy = "Terraform"
      Module    = "vortex-aws-storage-cloudwatch-ttl-guard"
    },
    var.tags
  )
}

# 1. EBS Volumes enforcing gp3 (legacy gp2 rejected at plan time by variable validation)
resource "aws_ebs_volume" "guarded" {
  for_each = var.ebs_volumes

  availability_zone = each.value.availability_zone
  size              = each.value.size_gb
  type              = each.value.type
  iops              = each.value.type == "gp3" ? each.value.iops : null
  throughput        = each.value.type == "gp3" ? each.value.throughput : null
  encrypted         = each.value.encrypted

  tags = merge(local.common_tags, {
    Name = each.key
  })
}

# 2. CloudWatch Log Groups enforcing bounded 14–30d TTL (blocks Never Expire drift)
resource "aws_cloudwatch_log_group" "bounded" {
  for_each = var.cloudwatch_log_groups

  name              = each.value.name
  retention_in_days = each.value.retention_in_days

  tags = local.common_tags
}

# 3. AWS Data Lifecycle Manager (DLM) automated EBS snapshot TTL expiry
resource "aws_iam_role" "dlm_lifecycle" {
  count = var.enable_dlm_snapshot_policy ? 1 : 0

  name = "${var.name_prefix}-dlm-role"
  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect    = "Allow"
      Principal = { Service = "dlm.amazonaws.com" }
      Action    = "sts:AssumeRole"
    }]
  })
  tags = local.common_tags
}

resource "aws_iam_role_policy" "dlm_lifecycle" {
  count = var.enable_dlm_snapshot_policy ? 1 : 0

  name = "${var.name_prefix}-dlm-policy"
  role = aws_iam_role.dlm_lifecycle[0].id
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Effect = "Allow"
        Action = [
          "ec2:CreateSnapshot",
          "ec2:CreateSnapshots",
          "ec2:DeleteSnapshot",
          "ec2:DescribeInstances",
          "ec2:DescribeVolumes",
          "ec2:DescribeSnapshots"
        ]
        Resource = "*"
      },
      {
        Effect   = "Allow"
        Action   = ["ec2:CreateTags"]
        Resource = "arn:aws:ec2:*::snapshot/*"
      }
    ]
  })
}

resource "aws_dlm_lifecycle_policy" "ebs_snapshot_ttl" {
  count = var.enable_dlm_snapshot_policy ? 1 : 0

  description        = "Automated daily EBS snapshot rotation with ${var.dlm_retain_count}-snapshot expiry TTL"
  execution_role_arn = aws_iam_role.dlm_lifecycle[0].arn
  state              = "ENABLED"

  policy_details {
    resource_types = ["VOLUME"]
    target_tags    = var.dlm_target_tags

    schedule {
      name = "daily-bounded-retention"

      create_rule {
        interval      = 24
        interval_unit = "HOURS"
        times         = ["03:00"]
      }

      retain_rule {
        count = var.dlm_retain_count
      }

      copy_tags = true
    }
  }

  tags = local.common_tags
}
aws-storage-cloudwatch-ttl-guard/variables.tf 71 lines · Plan-Time Validation Guards
variable "name_prefix" {
  type        = string
  description = "Prefix applied to IAM roles and DLM lifecycle policies."
  default     = "vortex-storage-ttl"
}

variable "ebs_volumes" {
  type = map(object({
    availability_zone = string
    size_gb           = number
    type              = optional(string, "gp3")
    iops              = optional(number, 3000)
    throughput        = optional(number, 125)
    encrypted         = optional(bool, true)
  }))
  description = "Managed EBS volumes with guardrails rejecting legacy gp2 volumes."
  default     = {}

  validation {
    condition     = alltrue([for v in values(var.ebs_volumes) : v.type != "gp2"])
    error_message = "Legacy gp2 EBS volumes are blocked by FinOps policy. Use gp3 (20% lower base cost, 3,000 baseline IOPS)."
  }
}

variable "cloudwatch_log_groups" {
  type = map(object({
    name              = string
    retention_in_days = optional(number, 30)
  }))
  description = "CloudWatch Log Groups with bounded retention (never infinite)."
  default     = {}

  validation {
    condition = alltrue([
      for lg in values(var.cloudwatch_log_groups) :
      contains([1, 3, 5, 7, 14, 30, 60, 90], lg.retention_in_days)
    ])
    error_message = "All CloudWatch Log Groups must specify a bounded AWS retention enum between 1 and 90 days (14 or 30 recommended)."
  }
}

variable "enable_dlm_snapshot_policy" {
  type        = bool
  description = "Enable AWS Data Lifecycle Manager (DLM) automated EBS snapshot rotation and expiry."
  default     = true
}

variable "dlm_target_tags" {
  type        = map(string)
  description = "Resource tags selecting EBS volumes governed by the DLM snapshot TTL policy."
  default = {
    BackupTier = "standard"
  }
}

variable "dlm_retain_count" {
  type        = number
  description = "Number of daily snapshots to retain before automatic expiry (default: 14 days)."
  default     = 14

  validation {
    condition     = var.dlm_retain_count >= 1 && var.dlm_retain_count <= 90
    error_message = "dlm_retain_count must be between 1 and 90 snapshots."
  }
}

variable "tags" {
  type        = map(string)
  description = "Additional tags applied to all created resources."
  default     = {}
}
aws-storage-cloudwatch-ttl-guard/outputs.tf 14 lines · Outputs
output "ebs_volume_ids" {
  value       = { for k, v in aws_ebs_volume.guarded : k => v.id }
  description = "Map of gp3-enforced EBS volume IDs."
}

output "cloudwatch_log_group_arns" {
  value       = { for k, v in aws_cloudwatch_log_group.bounded : k => v.arn }
  description = "Map of bounded-retention CloudWatch Log Group ARNs."
}

output "dlm_lifecycle_policy_id" {
  value       = try(aws_dlm_lifecycle_policy.ebs_snapshot_ttl[0].id, null)
  description = "ID of the AWS Data Lifecycle Manager snapshot expiry policy (if enabled)."
}
aws-storage-cloudwatch-ttl-guard/versions.tf 10 lines · Provider Constraints
terraform {
  required_version = ">= 1.5.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.0"
    }
  }
}
Example Module Invocation (Terraform) HCL Usage
module "storage_ttl_guard" {
  source = "./aws-storage-cloudwatch-ttl-guard"

  name_prefix = "prod-finops"
  ebs_volumes = {
    postgres-data = {
      availability_zone = "eu-central-2a"
      size_gb           = 500
      type              = "gp3"
      iops              = 6000
      throughput        = 250
    }
  }
  cloudwatch_log_groups = {
    eks-app = {
      name              = "/aws/containerinsights/prod-eks/application"
      retention_in_days = 30
    }
  }
  enable_dlm_snapshot_policy = true
  dlm_retain_count           = 14
}
Module 04 · Terraform AWS >= 5.40 + GitHub Actions · MIT License

GitHub Actions Ephemeral AWS ARM64 Spot Guard

open-source-kit/github-actions-arm64-spot-guard/

Eliminates 3x–4x AI-driven GitHub Actions CI/CD bill spikes by routing heavy build/test jobs onto scale-to-zero AWS Graviton (arm64) Spot runners (IMDSv2 required, scoped OIDC role, price-capacity-optimized) paired with concurrency: cancel-in-progress: true workflow guards.

60%–80% CI Compute Cut Scale-to-Zero Graviton Spot · Scoped OIDC · Zero Static AWS Keys
github-actions-arm64-spot-guard/main.tf 141 lines · HCL / Terraform
locals {
  common_tags = merge(
    {
      ManagedBy = "Terraform"
      Module    = "vortex-github-actions-arm64-spot-guard"
    },
    var.tags
  )
}

# 1. Zero-Ingress Security Group for Private Ephemeral Runners
resource "aws_security_group" "runner" {
  name        = "${var.name_prefix}-sg"
  description = "Egress-only security group for ephemeral GitHub Actions ARM64 Spot runners"
  vpc_id      = var.vpc_id

  egress {
    description = "Outbound HTTPS to GitHub API, ECR, and package registries"
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags = merge(local.common_tags, {
    Name = "${var.name_prefix}-sg"
  })
}

# 2. Scoped GitHub Actions OIDC Role (Zero Static AWS Access Keys)
resource "aws_iam_role" "github_oidc" {
  name = "${var.name_prefix}-oidc-role"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect    = "Allow"
      Principal = { Federated = var.oidc_provider_arn }
      Action    = "sts:AssumeRoleWithWebIdentity"
      Condition = {
        StringEquals = {
          "token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
        }
        StringLike = {
          "token.actions.githubusercontent.com:sub" = "repo:${var.github_org}/${var.github_repo}:*"
        }
      }
    }]
  })

  tags = local.common_tags
}

# 3. Hardened ARM64 Spot Launch Template (IMDSv2 Required, Encrypted gp3, No Public IP)
resource "aws_launch_template" "arm64_spot" {
  name_prefix            = "${var.name_prefix}-"
  image_id               = var.ami_id
  instance_type          = var.runner_instance_types[0]
  update_default_version = true

  metadata_options {
    http_endpoint               = "enabled"
    http_tokens                 = "required"
    http_put_response_hop_limit = 1
  }

  network_interfaces {
    associate_public_ip_address = false
    delete_on_termination       = true
    security_groups             = [aws_security_group.runner.id]
  }

  block_device_mappings {
    device_name = "/dev/xvda"
    ebs {
      volume_size           = var.root_volume_size_gb
      volume_type           = "gp3"
      iops                  = 3000
      throughput            = 125
      encrypted             = true
      delete_on_termination = true
    }
  }

  tag_specifications {
    resource_type = "instance"
    tags = merge(local.common_tags, {
      Name = "${var.name_prefix}-ephemeral"
      Arch = "arm64"
    })
  }

  tags = local.common_tags
}

# 4. Scale-to-Zero Mixed-Instance ARM64 Spot Auto Scaling Group
resource "aws_autoscaling_group" "arm64_spot" {
  name                  = "${var.name_prefix}-asg"
  min_size              = 0
  desired_capacity      = 0
  max_size              = var.max_runner_count
  vpc_zone_identifier   = var.private_subnet_ids
  capacity_rebalance    = true
  max_instance_lifetime = 86400

  mixed_instances_policy {
    instances_distribution {
      on_demand_base_capacity                  = 0
      on_demand_percentage_above_base_capacity = 0
      spot_allocation_strategy                 = "price-capacity-optimized"
    }

    launch_template {
      launch_template_specification {
        launch_template_id = aws_launch_template.arm64_spot.id
        version            = "$Latest"
      }

      dynamic "override" {
        for_each = var.runner_instance_types
        content {
          instance_type = override.value
        }
      }
    }
  }

  dynamic "tag" {
    for_each = local.common_tags
    content {
      key                 = tag.key
      value               = tag.value
      propagate_at_launch = true
    }
  }
}
github-actions-arm64-spot-guard/variables.tf 72 lines · Input Validation Guards
variable "vpc_id" {
  type        = string
  description = "Target AWS VPC ID where ephemeral GitHub Actions ARM64 Spot runners launch."
}

variable "private_subnet_ids" {
  type        = list(string)
  description = "Private subnet IDs across multiple Availability Zones for Spot capacity diversification."

  validation {
    condition     = length(var.private_subnet_ids) >= 2
    error_message = "Provide at least two private subnets across distinct AZs to maximize Spot availability."
  }
}

variable "ami_id" {
  type        = string
  description = "ARM64 Amazon Linux 2023 or Ubuntu 24.04 AMI ID baked with the GitHub Actions runner binary."
}

variable "github_org" {
  type        = string
  description = "GitHub organization or owner slug allowed to assume the OIDC runner role."
}

variable "github_repo" {
  type        = string
  description = "Repository name (or '*' for org-wide runners) scoped in the OIDC sub claim."
}

variable "oidc_provider_arn" {
  type        = string
  description = "ARN of the existing AWS IAM OIDC provider for token.actions.githubusercontent.com."
}

variable "runner_instance_types" {
  type        = list(string)
  description = "Graviton ARM64 instance types ordered for price-capacity-optimized Spot allocation."
  default     = ["c7g.large", "m7g.large", "c6g.large", "m6g.large"]
}

variable "max_runner_count" {
  type        = number
  description = "Hard upper bound on concurrent ephemeral Spot runners to prevent runaway CI loops."
  default     = 12
}
github-actions-arm64-spot-guard/workflow-example.yml 29 lines · GitHub Actions YAML
name: CI — ARM64 Spot & Concurrency Guard

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

concurrency:
  group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

permissions:
  id-token: write
  contents: read

jobs:
  test-and-build:
    runs-on: [self-hosted, linux, arm64, spot]
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4
      - name: Run test suite on Graviton ARM64 Spot
        run: |
          uname -m
          echo "Executing build & unit tests at ~65-80% lower compute cost than hosted runners"
github-actions-arm64-spot-guard/outputs.tf 20 lines · Outputs
output "runner_security_group_id" {
  description = "Egress-only security group ID attached to ephemeral ARM64 Spot runners."
  value       = aws_security_group.runner.id
}

output "github_oidc_role_arn" {
  description = "Least-privilege IAM Role ARN assumed via GitHub Actions OIDC."
  value       = aws_iam_role.github_oidc.arn
}

output "launch_template_id" {
  description = "Launch Template ID for hardened ARM64 gp3 Spot runners."
  value       = aws_launch_template.arm64_spot.id
}

output "autoscaling_group_name" {
  description = "Scale-to-zero mixed-instance Spot Auto Scaling Group name."
  value       = aws_autoscaling_group.arm64_spot.name
}
github-actions-arm64-spot-guard/versions.tf 10 lines · Provider Constraints
terraform {
  required_version = ">= 1.5.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.40.0"
    }
  }
}
Zero Credentials · Zero Infosec Tickets · 15 Minutes

Want Us to Spot 2–3 Live Leaks on Your Real Bill?

Upload 2–3 redacted AWS Cost Explorer or GitHub Actions screenshots for a call-free 4-minute Loom teardown in 24h — or share your screen live for 15 minutes (08:00–22:30 CET). Zero IAM setup required before we pinpoint real leaks; first 2 Founding Cohort slots are open at $500–$1,000 (or $0 upfront + capped share), and standard Fixed-Fee Sprints ($2,500–$8,500) carry a Written 3x Annualized Savings Guarantee.

Ask Cloud Architect
Book 15-Min Live Cost Explorer Teardown (Zero IAM) →
Ask about any Terraform/Karpenter module or fixed-fee sprint below