[donny@scyber ~]$ cat ./blog/aws-vpc-ipam-solution.md

Hierarchical, Multi-Region AWS VPC IPAM with Terraform

July 26, 2025 8 min read
AWS Infrastructure Terraform

How I built hierarchical, multi-Region IP address management on AWS VPC IPAM with Terraform — 67 pools, cross-account sharing, and a Streamlit planning tool that does the subnet math for you.

## The Challenge: IP Management Across Accounts and Regions

Plenty of organizations track their AWS IP space in a spreadsheet, and it works right up until two teams in two accounts pick overlapping CIDRs. AWS is blunt about what happens next: a peering request between VPCs with overlapping ranges comes back with a status of failed, full stop. There's no route table entry that fixes it — one side has to be renumbered, and by then both VPCs are usually carrying production traffic.

I've seen enterprises struggle with this repeatedly, and it's worst when scaling into new Regions or partway through a migration. The reason is arithmetic rather than carelessness: every account, Region, environment, and business unit multiplies the number of ranges somebody has to keep straight, and a manual record falls behind the infrastructure it's supposed to describe.

This one started on an engagement, not as a weekend project. The AWS footprint had grown for about a decade without a central plan behind it — six Regions across three geographies, hundreds of network resources, and no single place that authoritatively said which ranges were already spoken for. So I built an Amazon VPC IP Address Manager (IPAM) solution to move all of it into Terraform: the hierarchy, the allocation rules, and the cross-account sharing, defined in code and reviewable before anything gets created.

The part I didn't expect was how little prior art there was. I went looking for an existing pattern to adapt and came up empty — nothing published covered a hierarchical, multi-Region IPAM layout at this shape. Building it from scratch is the reason it ended up as a published AWS Prescriptive Guidance pattern instead of staying in a private repo.

## Solution Architecture: Four-Tier Hierarchical Design

The pool structure is four tiers deep, shaped to match how organizations actually divide their networks. The diagram traces it from the Configurator through to deployment:

AWS VPC IPAM Architecture with IPAM Configurator - Complete workflow from Streamlit application to Terraform deployment
Complete AWS VPC IPAM Architecture and Data Flow
Top-Level Pool (Global CIDR: 10.0.0.0/8)
├── Regional Pools (per AWS region: 10.0.0.0/12, 10.16.0.0/12, …)
│   ├── Business Unit Pools (per BU: 10.0.0.0/14, 10.4.0.0/14, …)
│   │   └── Environment Pools (dev/qa/prod: 10.0.0.0/16, 10.1.0.0/16, …)

Why bother with four tiers instead of a flat list of pools:

  • Organizational Alignment: Matches business unit and environment structure
  • Scalable Governance: Policies applied at appropriate hierarchy levels
  • Conflict Prevention: Automatic CIDR containment validation
  • Multi-Region Consistency: Centralized control with regional allocation

## The Innovation: IPAM Configurator Tool

The centerpiece is the "IPAM Configurator" — a Streamlit web app for laying out the pool hierarchy before any of it becomes Terraform.

Donny's IPAM Configurator Demo - Complete Streamlit application workflow
Donny's IPAM Configurator: Demo

Planning a hierarchy like this by hand means subnet math in a spreadsheet, and the mistakes don't surface until Terraform rejects them. The Configurator does the math and shows you the tree while you're still deciding.

Key Configurator Features:

  • • Interactive Web Interface with real-time validation
  • • Automated CIDR calculation with containment checking
  • • Visual representation via Sunburst diagrams
  • • Terraform tfvars file generation
  • • Drag-and-drop resource ordering
  • • Flexible reservation strategies
  • • Multi-tab workflow design

The tool is built using modern Python technologies including Streamlit for the web interface, Pandas for data manipulation, Plotly for visualization, and NetworkX for graph operations. The core logic handles complex CIDR validation and hierarchical allocation calculations that would typically require manual verification.

# Live Demo: Complete Workflow

Watch this complete demonstration showing the entire process from cloning the AWS Samples repository to deploying the IPAM solution with Terraform:

Demo covers: Repository setup → IPAM Configurator → Terraform deployment → AWS Console verification

## Technical Implementation Deep Dive

The Terraform is split into modules, with validation logic kept separate so the hierarchy rules are readable on their own:

AWS Resources

  • • Amazon VPC IPAM instance
  • • IPAM scopes for private IP management
  • • Hierarchical IPAM pools (~67 pools)
  • • AWS RAM resource shares
  • • Cross-account principal associations

Terraform Modules

  • • Root orchestration module
  • • Core IPAM hierarchy module
  • • Standardized tags module
  • • Validation logic module
  • • Cross-region compatibility

The hardest part was the validation logic. The solution checks CIDR well-formedness, verifies containment at every level of the hierarchy, and detects conflicts before anything is created.

The simplest, most portable guardrail validates a single variable — it works on every Terraform version because the condition only references the variable it's attached to:

variable "top_level_cidr" {
  type        = string
  description = "Global CIDR for the top-level IPAM pool (e.g. 10.0.0.0/8)."

  validation {
    # Must be a syntactically valid IPv4 CIDR...
    condition     = can(cidrhost(var.top_level_cidr, 0))
    error_message = "top_level_cidr must be a valid IPv4 CIDR, e.g. 10.0.0.0/8."
  }

  validation {
    # ...and broad enough to carve regional/BU/env pools beneath it.
    condition     = tonumber(split("/", var.top_level_cidr)[1]) <= 12
    error_message = "top_level_cidr prefix must be /12 or larger (smaller number) to leave room for the hierarchy."
  }
}

Validating that one pool actually fits inside another means comparing two variables in a single condition. That cross-variable reference requires Terraform 1.9+ (earlier versions reject a validation block that references anything but its own variable). Note the explicit tonumber()split() returns strings:

# Terraform >= 1.9: a validation rule may reference other variables.
variable "regional_prefix_length" {
  type        = number
  description = "Prefix length for each regional pool (e.g. 12 for a /12)."

  validation {
    condition = (
      var.regional_prefix_length > tonumber(split("/", var.top_level_cidr)[1])
      && var.regional_prefix_length <= 28
    )
    error_message = "Regional prefix must be longer (more specific) than the top-level CIDR and no longer than /28."
  }
}

🚀 Try It Yourself:

The complete solution is available as an AWS Sample on GitHub. Clone the repository and follow the demo above to deploy your own enterprise IPAM solution:

git clone https://github.com/aws-samples/sample-amazon-vpc-ipam-terraform

## Enterprise Integration Patterns

A few integration points matter if you're dropping this into an existing AWS setup:

AWS Organizations Integration

AWS Resource Access Manager (RAM) shares the IPAM pools across accounts in the organization. This enables centralized governance while allowing distributed teams to provision VPCs using organization-managed IP space.

Account Factory for Terraform (AFT) Compatibility

For organizations using AFT, this IPAM solution can be deployed as a global customization, providing immediate IP management capabilities for newly provisioned accounts.

Downstream VPC Provisioning

VPC modules can directly reference IPAM pools using data sources, eliminating manual CIDR specification and ensuring automatic compliance with organizational IP allocation policies.

# VPC integration example
resource "aws_vpc" "main" {
  ipv4_ipam_pool_id   = data.aws_vpc_ipam_pool.environment.id
  ipv4_netmask_length = 18
  
  tags = {
    Name = "production-vpc"
    Environment = "prod"
  }
}

## Operational Excellence & Governance

Beyond the technical implementation, this solution addresses critical operational requirements for enterprise environments:

Compliance & Governance

  • Auto-import capabilities for existing VPCs and subnets into appropriate pools
  • Policy-based allocation rules preventing overlapping address space
  • Reserved CIDR functionality for infrastructure and future expansion

Monitoring & Observability

  • CloudWatch integration for IPAM utilization metrics
  • Audit trails for all IP allocation and deallocation events
  • Compliance reporting for organizational IP usage patterns

Cost Optimization

One correction worth making here: this architecture requires the IPAM Advanced Tier, not the Free Tier. Private-scope pools, pools with locales outside the IPAM home Region, and pool allocations to non-owner accounts are all Advanced-Tier features, and this design uses all three. Advanced Tier bills per active IP per hour, so the cost work that actually matters is resource tagging for allocation across business units and environments — and knowing your active IP count before you turn it on.

## Real-World Impact & Lessons Learned

Building this IPAM solution taught me several important lessons about enterprise infrastructure automation:

The Power of Visual Planning Tools

The Configurator collapsed network planning from multi-week cycles into hours. Sunburst visualization, drag-and-drop reorganization, real-time validation, and generated .tfvars output replace the spreadsheet-and-subnet-math version of this work.

Validation is Critical

Validation at every level of the hierarchy was the least glamorous part of this build and the part that prevents the most damage. A bad CIDR caught by a Terraform precondition costs seconds. The same mistake caught after the pools are allocated means deprovisioning in dependency order.

Enterprise Integration Patterns Matter

Solutions that don't integrate well with existing enterprise patterns and workflows will struggle for adoption. This IPAM solution was designed from the ground up to work with AWS Organizations, AFT, and common enterprise Terraform patterns.

## Wrapping Up

What this bought, concretely: adding a Region or a business unit is a change to a variables file instead of a negotiation with a spreadsheet, and the validation catches a bad CIDR before Terraform ever calls the API. The planning tool exists so the hierarchy gets designed once, deliberately, instead of accumulating.

If you want to go deeper, the full pattern is public: the AWS Prescriptive Guidance write-up covers the architecture decisions, and the Terraform is open-sourced on aws-samples so you can read it, fork it, and adapt the hierarchy to your own account and region layout.

Read the pattern and grab the code:

DS
author.profile

Donny Schreiber

Cloud and product security engineer at AWS, based in Boulder, Colorado. I write about cloud security, DevSecOps, infrastructure-as-code, and the security side of AI — drawn from daily practice.

AWS Expert Infrastructure Terraform
# related_posts.available()
about-me.md

About Me: From Enterprise Security to Cloud & AI Security Engineering

How I went from enterprise cybersecurity to a security engineer at AWS — and the self-taught curiosity behind it.

Published July 26, 2025
vibe-coding-security.md

The Security Side of Vibe Coding

What AI-generated code gets wrong — real incidents and practical guardrails.

Published February 13, 2026