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.
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 = {
<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))
cidr_authorization_context = optional(map(string))
sub_pools = optional(any)
})
}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.
| Name | Version |
|---|---|
| terraform | >= 0.15.0 |
| aws | >= 3.73.0 |
| Name | Version |
|---|---|
| aws | >= 3.73.0 |
| Name | Source | Version |
|---|---|---|
| level_one | ./modules/sub_pool | n/a |
| level_three | ./modules/sub_pool | n/a |
| level_two | ./modules/sub_pool | n/a |
| level_zero | ./modules/sub_pool | n/a |
| Name | Type |
|---|---|
| aws_vpc_ipam.main | resource |
| aws_region.current | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| top_cidr | Top-level CIDR blocks. | list(string) |
n/a | yes |
| address_family | IPv4/6 address family. | string |
"ipv4" |
no |
| create_ipam | Determines whether to create an IPAM. If false, you must also provide a var.ipam_scope_id. |
bool |
true |
no |
| ipam_scope_id | (Optional) Required if var.ipam_id is set. Determines which scope to deploy pools into. |
string |
null |
no |
| ipam_scope_type | Which scope type to use. Valid inputs include public or private. You can alternatively provide your own scope ID. |
string |
"private" |
no |
| pool_configurations | A multi-level, nested map describing nested IPAM pools. Can nest up to three levels with the top level being outside the pool_configurations. This attribute is quite complex, see README.md for further explanation. |
any |
{} |
no |
| top_auto_import | auto_import setting for top-level pool. |
bool |
null |
no |
| top_cidr_authorization_context | A signed document that proves that you are authorized to bring the specified IP address range to Amazon using BYOIP. Document is not stored in the state file. For more information, refer to https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr#cidr_authorization_context. | any |
null |
no |
| top_description | Description of top-level pool. | string |
"" |
no |
| top_ram_share_principals | Principals to create RAM shares for top-level pool. | list(string) |
null |
no |
| Name | Description |
|---|---|
| ipam_info | If created, ouput the IPAM object information. |
| operating_regions | List of all IPAM operating regions. |
| pool_level_0 | Map of all pools at level 0. |
| pool_names | List of all pool names. |
| pools_level_1 | Map of all pools at level 1. |
| pools_level_2 | Map of all pools at level 2. |
| pools_level_3 | Map of all pools at level 3. |
