Skip to content

Terraform solution for multi-account, multi-region hierarchical Amazon VPC IPAM with AWS RAM sharing and a Streamlit-based config tool for accelerated network planning and`.tfvars` generation.

License

Notifications You must be signed in to change notification settings

aws-samples/sample-amazon-vpc-ipam-terraform

Sample Terraform Implementation for Hierarchical IPAM on AWS

AWS Terraform Python

This solution provides code to implement a shared, multi-account, multi-region, hierarchical Amazon VPC IP Address Manager (IPAM) specification using Terraform. Alongside the included companion Streamlit web application (Python), AWS cloud architects, engineers, and/or developers can vastly accelerate VPC/network planning, IP address space visualization, and the eventual Terraform deployment of their Amazon VPC IPAM specification. The specification is shared with AWS Organizations using AWS Resource Access Manager (RAM), and guidance for potential use in other Terraform modules — e.g., with Account Factory for Terraform (AFT) — is provided within this repository's README.

IPAM Configurator

Table of Contents


Executive Summary

This Terraform implementation provides a robust foundation for enterprise-grade IP address management across your AWS cloud infrastructure. By deploying a hierarchical, multi-region IPAM architecture integrated with AWS Resource Access Manager (RAM), it enables organizations to:

  • Automate IP address allocation across regions, business units, and environments
  • Enforce organizational network policies through programmatic validation
  • Scale network infrastructure efficiently as business requirements evolve
  • Reduce operational overhead through centralized management of IP address spaces
  • Accelerate cloud-native workload deployments with self-service CIDR allocation
  • Prevent address conflicts through policy-based controls and validation

This solution is designed for engineering teams who need to manage complex AWS environments with multiple accounts, regions, and business domains while maintaining consistent network governance.

Diagram: IPAM Deployment Topology & Example Usage

Example IPAM Usage

  1. Developer is deploying a new VPC and requests a /23 CIDR block from IPAM in Region A, for Business Unit Y, in Environment 3.
  2. The IPAM specification contains a pool for Region A, defined with the CIDR block of 10.176.0.0/15.
  3. Within the Region A pool, the specification contains a nested pool for Business Unit Y ("Pool AY"), defined as 10.177.0.0/16.
  4. Within "Pool AY", the specification contains another nested pool for Environment 3 ("Pool AY3"), defined as 10.177.128.0/18.
  5. Within the developer's target pool ("Pool AY3"), IPAM has two existing CIDR allocations — 10.177.128.0/23 and 10.177.130.0/22. The next-available /23 CIDR block is automatically calculated.
  6. The next-available /23 CIDR block is calculated as 10.177.134.0/23, is provided for the developer's resource, and is automatically compliant with the IPAM specification (for "Pool AY3").

Architecture Overview

What is IPAM?

IP Address Management (IPAM) is how organizations plan, track, and manage IP address spaces. It’s essential for keeping networks organized, avoiding conflicts, and enforcing policies—especially as environments grow more complex.

Common IPAM benefits
  • Centralized visibility into address usage
  • Automated assignment to prevent conflicts
  • Hierarchical organization for governance
  • Policy enforcement for compliance
  • Integration with DNS and DHCP

What is Amazon VPC IPAM?

Amazon VPC IPAM is a managed feature (of Amazon VPC) that simplifies planning, tracking, allocating, and monitoring IP addresses for your AWS workloads. It replaces spreadsheets with automation and visibility, and is built for scale.

Amazon VPC IPAM benefits checklist
  • Centralized management across accounts and regions
  • Automated CIDR allocation for VPCs and subnets
  • Hierarchical pools for organizational alignment
  • Integration with AWS Organizations and RAM
  • Near-real-time monitoring and audit trails

Core Architectural Concepts

This solution uses several AWS constructs to organize and govern IP space:

Concept Purpose
IPAM Service Central control, deployed in the primary region
IPAM Scopes Separate public and private address management
IPAM Pools Hierarchical CIDR collections for allocation
Pool Sharing Cross-account access via AWS RAM
Resource Discovery Finds existing resources automatically
Compliance Checking Validates CIDR assignments against policies
Diagram: IPAM Logical Constructs

IPAM Logical Constructs


Technical Design

Hierarchical Pool Structure

By default, this solution is developed to employ a four-tier, nested pool hierarchy:

  1. Top-Level (Global) Pool: Entire organizational IP space
  2. Regional Pools: Allocations per AWS region, within the top-level pool
  3. Business Unit Pools: Allocations per business unit/domain (marketing, finance), within each regional pool
  4. Environment Pools: Allocations per "SDLC" environment (dev, qa, prod), within each business unit pool
Example: Hierarchical Structure
Top-Level Pool (10.0.0.0/8)
├── Regional Pool - us-east-1 (10.0.0.0/12)
│   ├── Business Unit - Finance (10.0.0.0/14)
│   │   ├── Environment - Dev (10.0.0.0/16)
│   │   ├── Environment - QA (10.0.2.0/16)
│   │   ├── Environment - Core (10.0.4.0/16)
│   │   └── Environment - Prod (10.0.6.0/16)
│   └── Business Unit - Marketing (10.0.8.0/14)
│       ├── Environment - Dev (10.0.8.0/16)
│       └── ... (additional environments)
└── Regional Pool - eu-west-1 (10.16.0.0/12)
    └── ... (additional business units and environments)
Why this matters
  • Every CIDR sits neatly inside its parent pool.
  • No overlaps — each team gets its own space.
  • Delegation is simple, but oversight stays centralized.
  • Subnetting is straightforward and efficient.

Multi-Region Deployment Topology

This solution deploys the IPAM service centrally in a primary region, while enabling management of additional AWS regions as operating regions. Each region receives a dedicated IPAM pool and is configured with locale-specific settings, which ensures efficient and centralized IP resource management across your AWS environment.

Table: Deployment Aspects
Aspect Description
Primary Region Deployment IPAM service is deployed in a single primary region.
Operating Regions Additional regions registered for IPAM resource management.
Regional Pool Assignment Each operating region receives a dedicated address pool from the top-level.
Cross-Region Management All operating regions are centrally managed.
Regional Locale Settings Each regional pool has a "locale" property tied to its region.

IPAM Compliance & Governance

This solution enables robust IP address compliance mechanisms by means of:

  1. Auto-Import: When IPAM pools are created, it’s recommended to allow IPAM to automatically import pre-existing resources (into respective pools)
  2. Compliance Checking: New and imported resources are monitored by IPAM for compliance with pool allocation rules and potential IP address overlap
  3. Nested Compliance: Resources may be non-compliant with direct pools but compliant with higher-level pools
  4. Remediation Options: Non-compliant resources can be excluded, reassigned, or have pools adjusted

As shown in the deployment topology diagram, VPC AY3-3 demonstrates a non-compliance scenario where the resource's CIDR doesn't fit within the range of its intended pool.

For more information on CIDR compliance monitoring in Amazon VPC IPAM, please review the documentation.


Implementation Guide

Prerequisites

Before deploying this IPAM solution, ensure your environment meets these requirements:

  1. AWS Organizations:

    • Your AWS environment must use AWS Organizations
    • The IPAM account must be a member of your organization
    • Resource sharing must be enabled at the organization level
  2. AWS Resource Access Manager (RAM):

  3. IAM Permissions:

    • The deploying identity requires permissions for:
      • IPAM management
      • RAM resource sharing
      • Organization access
      • VPC management
    • For details: AWS IPAM IAM Documentation
  4. Service Quotas:

    • Verify sufficient IPAM pool quota (default: 50)
    • This deployment with 6 regions, 2 business units, and 4 environments will create 67 pools
    • For details: AWS IPAM Quotas
  5. Network Design:

    • Prepare a comprehensive IP allocation plan
    • Confirm non-overlapping CIDR ranges for all regions, business units, and environments
    • For planning guidance: AWS IPAM Planning

Configuration Parameters

Expand details

Key configuration parameters for this solution include:

  1. Top-Level CIDR: The overall address space for your organization (e.g., 10.0.0.0/8)
  2. Operating Regions: AWS regions where IPAM will manage resources
  3. Regional IPAM Configurations: Per-region settings including:
    • Regional names and descriptions
    • Regional CIDR allocations
    • AWS region locale
  4. Business Unit Configurations: Per-BU settings including:
    • Business unit names and descriptions
    • BU-level CIDR allocations
  5. Environment Configurations: Per-environment settings including:
    • Environment names and descriptions
    • Environment-level CIDR allocations
    • Reserved CIDR blocks (see RESERVED-CIDRS.md for details)

Deployment Workflow

Expand details

The deployment process follows this general workflow:

  1. Module Instantiation: Include the IPAM module in your Terraform code
  2. Parameter Configuration: Set required variables for your organization
  3. Validation: Terraform validates CIDR relationships during plan phase
  4. IPAM Deployment: Creates the IPAM service in the primary region
  5. Pool Creation: Builds the hierarchical pool structure
  6. Resource Sharing: Configures RAM sharing for cross-account access
  7. Outputs: Produces references for downstream consumption

IPAM Configurator Tool

To accelerate and simplify planning and deployment processes, I have developed a companion, Streamlit-based "IPAM Configurator" tool (located in the ipam-figurator directory) that helps generate the necessary terraform.tfvars file based on your organizational requirements.

This companion tool will prove essential once you have your Amazon VPC network hierarchy planned — e.g., Top-Level CIDR, Operating Regions, Business Units, "SDLC" Environments. Here's a high-level overview of what the tool provides:

  • Interactive UI: The configurator provides a web-based interface for defining your IPAM hierarchy
  • Automated CIDR Planning: The tool calculates appropriate CIDR allocations based on your inputs
  • Visual Validation: Preview the IPAM structure before generating the configuration
  • Configuration Download: Export (or copy-paste) a ready-to-use terraform.tfvars file

To use the IPAM Configurator, clone the repo, change directories, then execute the run.sh script:

cd ipam-figurator
./run.sh

This will launch a local Streamlit application that will guide you through the configuration process. Once complete, you can download the generated terraform.tfvars file (or copy its contents) and use it with this Terraform module.

Once you have your '.tfvars' configuration, simply execute the stop.sh script to "tear-down":

./stop.sh

For more detailed information about the IPAM Configurator, see the README.


Module Structure

The repository is organized with the following structure:

  • Terraform Directory: Contains all Terraform code for the implementation
    • Root Module: Orchestrates the deployment and provides input variables
    • IPAM Module: Core implementation of the IPAM architecture
    • Tags Module: Standardized tagging for all resources
  • IPAM Configurator: Web-based tool for generating terraform.tfvars

Key files include:

  • terraform/main.tf: Primary module orchestration
  • terraform/variables.tf: Input variables for configuration
  • terraform/outputs.tf: Output values for downstream consumption
  • terraform/data.tf: Data sources for AWS resources
  • terraform/tags.tf: Tagging configuration
  • terraform/modules/ipam/main.tf: IPAM resource definitions
  • terraform/modules/ipam/locals.tf: Validation logic and transformations
  • terraform/modules/tags/main.tf: Tag standardization logic
  • ipam-figurator/: IPAM configuration generation tool

Deployed Resources

This solution deploys the following AWS resources:

  1. Core IPAM Resources:

    • Amazon VPC IPAM instance in the primary region
    • IPAM scope for private IP management
    • Four-tier hierarchy of IPAM pools:
      • Top-level pool for global address space
      • Regional pools for each operating region
      • Business unit pools within each region
      • Environment pools within each business unit
  2. Resource Sharing:

    • AWS RAM resource shares for all IPAM pools
    • RAM principal associations with your AWS Organization
    • RAM resource associations for all pools

Technical Features

Centralized Management

Expand details

This solution deploys a single IPAM instance in your primary AWS region that:

  • Provides a unified control plane for IP management
  • Supports registration of multiple operating regions
  • Centralizes logging and audit trails
  • Offers consistent policy enforcement
  • Maintains a single source of truth for IP allocation

Hierarchical IP Allocation

Expand details

The hierarchical pool structure enables:

  • Top-down address space planning: Start with the largest scope and segment progressively
  • Delegation of control: Business units can manage their allocations independently
  • Isolation of concerns: Each pool has a dedicated purpose and owner
  • Efficient utilization: CIDR blocks are allocated at appropriate sizes for their use

Resource Sharing & Integration

Expand details

AWS RAM integration provides:

  • Cross-account access to IPAM pools
  • Organizational-level permission management
  • Self-service CIDR allocation for application teams
  • Centralized policy enforcement with distributed execution

Validation & Enforcement

Expand details

Built-in validation logic ensures:

  • Environment CIDRs are contained within their parent business unit CIDRs
  • Business unit CIDRs are contained within their parent regional CIDRs
  • Regional CIDRs are contained within the top-level CIDR
  • No overlapping CIDRs within the same hierarchy level
  • Proper mapping of environments to their respective business units

Resource Tagging

This solution includes an additional, reusable submodule to facilitate standardized tagging for all AWS resources.


Integration Patterns

AWS Organizations Integration

This solution integrates with AWS Organizations natively. By design, all IPAM pools are shared across all organization accounts using AWS RAM — from a dedicated Network account, for example, to which this solution's Terraform manifests were applied. Consequently, all accounts in the Organization will have the ability to apply consistent IP addressing standards.

AFT Integration

For AWS Account Factory for Terraform (AFT) users, this solution might be used as an Account Customization in your Network account (or similar).

This will help ensure:

  1. You create and maintain a firm, centralized foundation for consistent network addressing for your accounts and workloads.
  2. You are providing stable references for network resources provisioned using other AFT customizations/manifests (e.g., a VPC module).

VPC Provisioning Integration

This solution lets you plug IPAM-managed pools directly into your VPC provisioning workflow. Terraform modules for VPC resource provisioning can reference pools programmatically, enabling automatic CIDR allocation with consistent, centralized address management.

Code: Example VPC module integration
# Data source to find the intended IPAM pool
data "aws_vpc_ipam_pool" "dev_pool" {
  filter {
    name   = "tag:Name"
    values = ["dev-environment-pool"]
  }
}

# Calling the VPC module
module "application_vpc" {
  source = "./modules/vpc"

  # Reference the intended IPAM pool
  ipam_pool_id        = data.aws_vpc_ipam_pool.dev_pool.id
  ipv4_netmask_length = 24  # Requests a /24 from the pool

  # Additional VPC configuration...
  name                = "dev-test-app-vpc"
  #...
}
How this helps
  1. VPCs get non-overlapping CIDRs, automatically assigned from the right pool
  2. Address assignments are consistent and centrally tracked
  3. No more manual subnet math or spreadsheet management

Advanced Usage

Special Network Requirements

For custom or edge-case scenarios, you can define configuration values directly within the module block -- i.e., via direct (inlined, explicit) values. The IPAM Configurator tool can generate the baseline configuration, which you can further tailor as needed.

Code: Example custom, partially-inlined configuration
####### variables.tf #######
variable "additional_reg_ipam_configs" {
  description = "Additional regional IPAM configs"
  type        = map(object({
    name        = string
    description = string
    cidr        = list(string)
    locale      = string
  }))
  default     = {}
}
# ...etc.

####### terraform.tfvars #######
additional_reg_ipam_configs = {
  "us-west-2" = {
    name        = "ipam-regional-us-west-2"
    description = "Regional IPAM Pool for US West (Oregon)"
    cidr        = ["10.64.0.0/12"]
    locale      = "us-west-2"
  }
  # ...other regions
}
# ...etc.

####### main.tf #######
module "ipam" {
  source = "./modules/ipam"

  # Inlined (explicit) values for custom requirements
  operating_regions = [
    "us-east-1",
    "us-west-2",
    "eu-west-1",
    "ap-northeast-1"
  ]
  top_name        = "enterprise-ipam-global"
  top_description = "Enterprise-wide Global IPAM Pool"

  # Partially-inlined: 'us-east-1' is inlined, others via 'merge()' with the new 'var.additional_reg_ipam_configs'
  reg_ipam_configs = merge(
    {
      us-east-1 = {
        name        = "ipam-regional-us-east-1"
        description = "Regional IPAM Pool for US East (N. Virginia)"
        cidr        = ["10.0.0.0/10"]
        locale      = "us-east-1"
      }
    },
    var.additional_reg_ipam_configs
  )

  # Inhereted defaults or shared values from existing variables
  top_cidr          = var.top_cidr
  bu_ipam_configs   = var.bu_ipam_configs
  env_ipam_configs  = var.env_ipam_configs
  organization_arn  = data.aws_organizations_organization.current.arn
  share_name        = var.share_name
  tags              = module.tags.tag_map
}

See the example tfvars file for additional insights into fully specified arguments.

Tip

Terraform does not support "spreading" maps — e.g., like JavaScript's { ...var }. So, as illustrated in my "partially-inlined" example (for reg_ipam_configs) above, I needed to declare a new variable (additional_reg_ipam_configs) in the variables.tf file, assign a value to the variable (or values, since additional_reg_ipam_configs is a map) in the terraform.tfvars file, and use merge() to combine the inlined and variable-driven maps.


Outputs Reference

This solution provides comprehensive outputs by default — e.g., for downstream consumption:

  1. IPAM Pool IDs:

    • Top-level pool ID
    • Regional pool IDs
    • Business unit pool IDs
    • Environment pool IDs
  2. CIDR Allocations:

    • Business unit CIDR blocks
    • Environment CIDR blocks
  3. RAM Resources:

    • Resource share ARNs
    • Principal associations
    • Resource associations

Security

See CONTRIBUTING for more information.


License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

Terraform solution for multi-account, multi-region hierarchical Amazon VPC IPAM with AWS RAM sharing and a Streamlit-based config tool for accelerated network planning and`.tfvars` generation.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •