Note: For information regarding the 2.0 upgrade see our upgrade guide.
This module helps deploy AWS IPAM including IPAM Pools, Provisioned CIDRs, and can help with sharing those pools via AWS RAM.
Built to accommodate a wide range of use cases, this Terraform module can deploy both simple and complex Amazon Virtual Private Cloud (Amazon VPC) IP Address Manager (IPAM) configurations. It supports both symmetrically nested, multi-Region deployments (most common IPAM designs) as well as asymmetically nested deployments.
Refer to the examples/ directory in this GitHub repository for examples.
The embedded example below describes a symmetrically nested pool structure, including its configuration, implementation details, requirements, and more.
Note: The diagram above is an example of the type of Pool design you can deploy using this module.
This module strongly relies on the var.pool_configuration
variable, which is a multi-level, nested map that describes how to nest your IPAM pools. It can accept most aws_vpc_ipam_pool
and aws_vpc_ipam_pool_cidr
attributes (detailed below) as well as RAM share pools (at any level) to valid AWS principals. Nested pools do not inherit attributes from their source pool(s), so all configuration options are available at each level. locale
is implied in sub pools after declared in a parent.
In this module, pools can be nested up to four levels, including one root pool and up to three nested pools. The root pool defines the address_family
variable. If you want to deploy an IPv4 and IPv6 pool structure, you must instantiate the module for each type.
The pool_configurations
variable is the structure of the other three levels. The sub_pool
submodule has a var.pool_config
variable that defines the structure that each pool can accept. The variable has the following structure:
pool_configurations = {
my_pool_name = {
description = "my pool"
cidr = ["10.0.0.0/16"]
locale = "us-east-1"
sub_pools = {
sandbox = {
cidr = ["10.0.48.0/20"]
ram_share_principals = [local.dev_ou_arn]
# ...any pool_config argument (below)
}
}
}
}
The key of a pool_config
variable is the name of the pool, followed by its attributes ram_share_principals
and a sub_pools
map, which is another nested pool_config
variable.
variable "pool_config" {
type = object({
cidr = list(string)
ram_share_principals = optional(list(string))
name = optional(string)
locale = optional(string)
allocation_default_netmask_length = optional(string)
allocation_max_netmask_length = optional(string)
allocation_min_netmask_length = optional(string)
auto_import = optional(string)
aws_service = optional(string)
description = optional(string)
publicly_advertisable = optional(bool)
allocation_resource_tags = optional(map(string))
tags = optional(map(string))
sub_pools = optional(any)
})
}
This module allows you to share invidual pools to any valid RAM principal. All levels of var.pool_configurations
accept an argument ram_share_principals
which should be a list of valid RAM share principals (org-id, ou-id, or account id).
Since resources are dynamically generated based on user configuration, we roll them into grouped outputs. For example, to get attributes off your level 2 pools:
The output pools_level_2
offers you a map of every pool where the name is the route of the tree keys example "corporate-us-west-2/dev"
.
To get a specific ID:
> module.basic.pools_level_2["corporate-us-west-2/dev"].id
"ipam-pool-0c816929a16f08747"
To get all IDs
> [ for pool in module.basic.pools_level_2: pool["id"]]
[
"ipam-pool-0c816929a16f08747",
"ipam-pool-0192c70b370384661",
"ipam-pool-037bb0524f8b3278e",
"ipam-pool-09400d26a6d1df4a5",
"ipam-pool-0ee5ebe8f8d2d7187",
]
By default, pool Name
tags and pool descriptions are implied from the name-hierarchy structure of the pool. For example, a pool with two parents us-east-1
and dev
has an implied name and description value of us-east-1/dev
. You can override either or both name and description at any pool level by specifying a name
or description
value.
IPAM pools do not inherit attributes from their parent pools. Locales cannot change from parent to child. For that reason, after a pool in the var.pool_configurations
variable defines a locale
value, all other child pools have an implied_locale
value.
The IPAM operating_region
variable must be set for the primary Region in your Terraform provider block and any Regions you want to set a locale
. For that reason, the value of the aws_vpc_ipam.operating_regions
variable is constructed by combining the pool_configurations
and data.aws_region.current.name
attributes.