Skip to content

Commit 4617b23

Browse files
authored
Merge pull request #41 from aws-ia/fix-top-name-tag
Fix top name tag
2 parents a7d508c + 8deae41 commit 4617b23

File tree

6 files changed

+106
-43
lines changed

6 files changed

+106
-43
lines changed

.header.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Terraform Module for Amazon VPC IP Address Manager on AWS
22

3-
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](images/asymmetrical_example.png).
3+
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](https://github.com/aws-ia/terraform-aws-ipam/blob/main/images/asymmetrical_example.png).
44

5-
Refer to the [examples/](./examples/) directory in this GitHub repository for examples.
5+
Refer to the [examples/](https://github.com/aws-ia/terraform-aws-ipam/blob/main/examples) directory in this GitHub repository for examples.
66

77
The embedded example below describes a symmetrically nested pool structure, including its configuration, implementation details, requirements, and more.
88

99
## Architecture
1010

11-
![symmetrically nested pool deployment](images/ipam_symmetrical.png)
11+
<p align="center">
12+
<img src="https://raw.githubusercontent.com/aws-ia/terraform-aws-ipam/main/images/ipam_symmetrical.png" alt="symmetrically nested pool deployment" width="100%">
13+
</p>
1214

1315
## Configuration
1416
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.
@@ -63,6 +65,34 @@ variable "pool_config" {
6365
}
6466
```
6567

68+
## RAM Sharing
69+
70+
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).
71+
72+
## Using Outputs
73+
74+
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:
75+
76+
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"`](https://github.com/aws-ia/terraform-aws-ipam/blob/a7d508cb0be2f68d99952682c2392b6d7d541d96/examples/single_scope_ipv4/main.tf#L28).
77+
78+
To get a specific ID:
79+
```
80+
> module.basic.pools_level_2["corporate-us-west-2/dev"].id
81+
"ipam-pool-0c816929a16f08747"
82+
```
83+
84+
To get all IDs
85+
```terraform
86+
> [ for pool in module.basic.pools_level_2: pool["id"]]
87+
[
88+
"ipam-pool-0c816929a16f08747",
89+
"ipam-pool-0192c70b370384661",
90+
"ipam-pool-037bb0524f8b3278e",
91+
"ipam-pool-09400d26a6d1df4a5",
92+
"ipam-pool-0ee5ebe8f8d2d7187",
93+
]
94+
```
95+
6696
## Implementation
6797

6898
### Implied pool names and descriptions

.tflint.hcl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
plugin "aws" {
55
enabled = true
6-
version = "0.12.0"
6+
version = "0.14.0"
77
source = "github.com/terraform-linters/tflint-ruleset-aws"
88
}
99

@@ -12,6 +12,15 @@ config {
1212
force = false
1313
}
1414

15+
## Ignored Rules:
16+
17+
rule "aws_vpc_ipam_pool_invalid_aws_service" {
18+
# https://github.com/terraform-linters/tflint-ruleset-aws/issues/357
19+
enabled = false
20+
}
21+
22+
## Enabled Rules
23+
1524
rule "terraform_required_providers" {
1625
enabled = true
1726
}

README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<!-- BEGIN_TF_DOCS -->
22
# Terraform Module for Amazon VPC IP Address Manager on AWS
33

4-
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](images/asymmetrical\_example.png).
4+
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](https://github.com/aws-ia/terraform-aws-ipam/blob/main/images/asymmetrical_example.png).
55

6-
Refer to the [examples/](./examples/) directory in this GitHub repository for examples.
6+
Refer to the [examples/](https://github.com/aws-ia/terraform-aws-ipam/blob/main/examples) directory in this GitHub repository for examples.
77

88
The embedded example below describes a symmetrically nested pool structure, including its configuration, implementation details, requirements, and more.
99

1010
## Architecture
1111

12-
![symmetrically nested pool deployment](images/ipam\_symmetrical.png)
12+
<p align="center">
13+
<img src="https://raw.githubusercontent.com/aws-ia/terraform-aws-ipam/main/images/ipam_symmetrical.png" alt="symmetrically nested pool deployment" width="100%">
14+
</p>
1315

1416
## Configuration
1517
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.
@@ -64,6 +66,34 @@ variable "pool_config" {
6466
}
6567
```
6668

69+
## RAM Sharing
70+
71+
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).
72+
73+
## Using Outputs
74+
75+
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:
76+
77+
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"`](https://github.com/aws-ia/terraform-aws-ipam/blob/a7d508cb0be2f68d99952682c2392b6d7d541d96/examples/single_scope_ipv4/main.tf#L28).
78+
79+
To get a specific ID:
80+
```
81+
> module.basic.pools_level_2["corporate-us-west-2/dev"].id
82+
"ipam-pool-0c816929a16f08747"
83+
```
84+
85+
To get all IDs
86+
```terraform
87+
> [ for pool in module.basic.pools_level_2: pool["id"]]
88+
[
89+
"ipam-pool-0c816929a16f08747",
90+
"ipam-pool-0192c70b370384661",
91+
"ipam-pool-037bb0524f8b3278e",
92+
"ipam-pool-09400d26a6d1df4a5",
93+
"ipam-pool-0ee5ebe8f8d2d7187",
94+
]
95+
```
96+
6797
## Implementation
6898

6999
### Implied pool names and descriptions
@@ -89,7 +119,7 @@ The IPAM `operating_region` variable must be set for the primary Region in your
89119

90120
| Name | Version |
91121
|------|---------|
92-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.73.0 |
122+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.17.1 |
93123

94124
## Modules
95125

@@ -116,12 +146,12 @@ The IPAM `operating_region` variable must be set for the primary Region in your
116146
| <a name="input_create_ipam"></a> [create\_ipam](#input\_create\_ipam) | Determines whether to create an IPAM. If `false`, you must also provide a var.ipam\_scope\_id. | `bool` | `true` | no |
117147
| <a name="input_ipam_scope_id"></a> [ipam\_scope\_id](#input\_ipam\_scope\_id) | (Optional) Required if `var.ipam_id` is set. Determines which scope to deploy pools into. | `string` | `null` | no |
118148
| <a name="input_ipam_scope_type"></a> [ipam\_scope\_type](#input\_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 |
119-
| <a name="input_pool_configurations"></a> [pool\_configurations](#input\_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 |
149+
| <a name="input_pool_configurations"></a> [pool\_configurations](#input\_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` in vars prefixed `top_`. If arugument descriptions are omitted, you can find them in the [official documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool#argument-reference).<br><br>- `ram_share_principals` = (optional, list(string)) of valid organization principals to create ram shares to.<br>- `name` = (optional, string) name to give the pool, the key of your map in var.pool\_configurations will be used if omitted.<br>- `description` = (optional, string) description to give the pool, the key of your map in var.pool\_configurations will be used if omitted.<br>- `cidr` = (optional, list(string)) list of CIDRs to provision into pool.<br><br>- `locale` = (optional, string) locale to set for pool.<br>- `auto_import` = (optional, string)<br>- `tags` = (optional, map(string))<br>- `allocation_default_netmask_length` = (optional, string)<br>- `allocation_max_netmask_length` = (optional, string)<br>- `allocation_min_netmask_length` = (optional, string)<br>- `allocation_resource_tags` = (optional, map(string))<br><br>The following arguments are available but only relevant for public ips<br>- `cidr_authorization_context` = (optional, map(string)) Details found in [official documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr#cidr_authorization_context).<br>- `aws_service` = (optional, string)<br>- `publicly_advertisable` = (optional, bool)<br><br>- `sub_pools` = (nested repeats of pool\_configuration object above) | `any` | `{}` | no |
120150
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to add to the aws\_vpc\_ipam resource. | `any` | `{}` | no |
121151
| <a name="input_top_auto_import"></a> [top\_auto\_import](#input\_top\_auto\_import) | `auto_import` setting for top-level pool. | `bool` | `null` | no |
122152
| <a name="input_top_cidr_authorization_context"></a> [top\_cidr\_authorization\_context](#input\_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 |
123153
| <a name="input_top_description"></a> [top\_description](#input\_top\_description) | Description of top-level pool. | `string` | `""` | no |
124-
| <a name="input_top_name"></a> [top\_name](#input\_top\_name) | Name of top-level pool. | `string` | `""` | no |
154+
| <a name="input_top_name"></a> [top\_name](#input\_top\_name) | Name of top-level pool. | `string` | `null` | no |
125155
| <a name="input_top_ram_share_principals"></a> [top\_ram\_share\_principals](#input\_top\_ram\_share\_principals) | Principals to create RAM shares for top-level pool. | `list(string)` | `null` | no |
126156

127157
## Outputs

examples/single_scope_ipv4/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module "basic" {
99
source = "../.."
1010

1111
top_cidr = ["10.0.0.0/8"]
12+
top_name = "basic ipam"
1213

1314
pool_configurations = {
1415
corporate-us-west-2 = {

main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ module "level_zero" {
5252
auto_import = var.top_auto_import
5353
description = var.top_description
5454
cidr_authorization_context = var.top_cidr_authorization_context
55-
tags = {}
5655
name = var.top_name
5756
}
5857
}

variables.tf

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
variable "pool_configurations" {
2-
description = "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."
32
type = any
4-
5-
# Below is an example of the actual expected structure for `pool_configurations`. type = any is currently being used, may adjust in the future
6-
7-
# type = object({
8-
# cidr = optional(list(string))
9-
# ram_share_principals = optional(list(string))
10-
# locale = optional(string)
11-
# allocation_default_netmask_length = optional(string)
12-
# allocation_max_netmask_length = optional(string)
13-
# allocation_min_netmask_length = optional(string)
14-
# auto_import = optional(string)
15-
# aws_service = optional(string)
16-
# description = optional(string)
17-
# name = optional(string)
18-
# publicly_advertisable = optional(bool)
19-
# allocation_resource_tags = optional(map(string))
20-
# tags = optional(map(string))
21-
# cidr_authorization_context = optional(map(string))
22-
23-
# sub_pools = (repeat of pool_configuration object above )
24-
# })
25-
default = {}
26-
27-
# Validate no more than 3 layers of sub_pools specified
28-
# TODO: fix validation, fails if less than 2 layers of pools
29-
# validation {
30-
# error_message = "Sub pools (sub_pools) is defined in the 3rd level of a nested pool. Sub pools can only be defined up to 3 levels."
31-
# condition = flatten([for k, v in var.pool_configurations : [for k2, v2 in v.sub_pools : [for k3, v3 in try(v2.sub_pools, []) : "${k}/${k2}/${k3}" if try(v3.sub_pools, []) != []]]]) == []
32-
# }
3+
default = {}
4+
description = <<-EOF
5+
A multi-level, nested map describing nested IPAM pools. Can nest up to three levels with the top level being outside the `pool_configurations` in vars prefixed `top_`. If arugument descriptions are omitted, you can find them in the [official documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool#argument-reference).
6+
7+
- `ram_share_principals` = (optional, list(string)) of valid organization principals to create ram shares to.
8+
- `name` = (optional, string) name to give the pool, the key of your map in var.pool_configurations will be used if omitted.
9+
- `description` = (optional, string) description to give the pool, the key of your map in var.pool_configurations will be used if omitted.
10+
- `cidr` = (optional, list(string)) list of CIDRs to provision into pool.
11+
12+
- `locale` = (optional, string) locale to set for pool.
13+
- `auto_import` = (optional, string)
14+
- `tags` = (optional, map(string))
15+
- `allocation_default_netmask_length` = (optional, string)
16+
- `allocation_max_netmask_length` = (optional, string)
17+
- `allocation_min_netmask_length` = (optional, string)
18+
- `allocation_resource_tags` = (optional, map(string))
19+
20+
The following arguments are available but only relevant for public ips
21+
- `cidr_authorization_context` = (optional, map(string)) Details found in [official documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr#cidr_authorization_context).
22+
- `aws_service` = (optional, string)
23+
- `publicly_advertisable` = (optional, bool)
24+
25+
- `sub_pools` = (nested repeats of pool_configuration object above)
26+
EOF
3327
}
3428

3529
variable "top_cidr" {
@@ -58,7 +52,7 @@ variable "top_description" {
5852
variable "top_name" {
5953
description = "Name of top-level pool."
6054
type = string
61-
default = ""
55+
default = null
6256
}
6357

6458
variable "top_cidr_authorization_context" {
@@ -104,4 +98,4 @@ variable "tags" {
10498
description = "Tags to add to the aws_vpc_ipam resource."
10599
type = any
106100
default = {}
107-
}
101+
}

0 commit comments

Comments
 (0)