Skip to content

Commit 0e8d251

Browse files
drewmullenbryantbiggs
authored andcommitted
add ipam ipv4 support
1 parent 6e356d2 commit 0e8d251

File tree

6 files changed

+166
-119
lines changed

6 files changed

+166
-119
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ No modules.
355355
| <a name="input_amazon_side_asn"></a> [amazon\_side\_asn](#input\_amazon\_side\_asn) | The Autonomous System Number (ASN) for the Amazon side of the gateway. By default the virtual private gateway is created with the current default Amazon ASN. | `string` | `"64512"` | no |
356356
| <a name="input_assign_ipv6_address_on_creation"></a> [assign\_ipv6\_address\_on\_creation](#input\_assign\_ipv6\_address\_on\_creation) | Assign IPv6 address on subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map\_public\_ip\_on\_launch | `bool` | `false` | no |
357357
| <a name="input_azs"></a> [azs](#input\_azs) | A list of availability zones names or ids in the region | `list(string)` | `[]` | no |
358-
| <a name="input_cidr"></a> [cidr](#input\_cidr) | (Optional) The IPv4 CIDR block for the VPC. | `string` | `"0.0.0.0/0"` | no |
358+
| <a name="input_cidr"></a> [cidr](#input\_cidr) | (Optional) The IPv4 CIDR block for the VPC. CIDR can be explicitly set or it can be derived from IPAM using `ipv4_netmask_length` & `ipv4_ipam_pool_id` | `string` | `"0.0.0.0/0"` | no |
359359
| <a name="input_create_database_internet_gateway_route"></a> [create\_database\_internet\_gateway\_route](#input\_create\_database\_internet\_gateway\_route) | Controls if an internet gateway route for public database access should be created | `bool` | `false` | no |
360360
| <a name="input_create_database_nat_gateway_route"></a> [create\_database\_nat\_gateway\_route](#input\_create\_database\_nat\_gateway\_route) | Controls if a nat gateway route should be created to give internet access to the database subnets | `bool` | `false` | no |
361361
| <a name="input_create_database_subnet_group"></a> [create\_database\_subnet\_group](#input\_create\_database\_subnet\_group) | Controls if database subnet group should be created (n.b. database\_subnets must also be set) | `bool` | `true` | no |
@@ -455,6 +455,7 @@ No modules.
455455
| <a name="input_intra_subnet_tags"></a> [intra\_subnet\_tags](#input\_intra\_subnet\_tags) | Additional tags for the intra subnets | `map(string)` | `{}` | no |
456456
| <a name="input_intra_subnets"></a> [intra\_subnets](#input\_intra\_subnets) | A list of intra subnets | `list(string)` | `[]` | no |
457457
| <a name="input_ipv4_ipam_pool_id"></a> [ipv4\_ipam\_pool\_id](#input\_ipv4\_ipam\_pool\_id) | (Optional) The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. | `string` | `null` | no |
458+
| <a name="input_ipv4_netmask_length"></a> [ipv4\_netmask\_length](#input\_ipv4\_netmask\_length) | (Optional) The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4\_ipam\_pool\_id. | `number` | `null` | no |
458459
| <a name="input_manage_default_network_acl"></a> [manage\_default\_network\_acl](#input\_manage\_default\_network\_acl) | Should be true to adopt and manage Default Network ACL | `bool` | `false` | no |
459460
| <a name="input_manage_default_route_table"></a> [manage\_default\_route\_table](#input\_manage\_default\_route\_table) | Should be true to manage default route table | `bool` | `false` | no |
460461
| <a name="input_manage_default_security_group"></a> [manage\_default\_security\_group](#input\_manage\_default\_security\_group) | Should be true to adopt and manage default security group | `bool` | `false` | no |

examples/ipam-vpc/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4242

4343
| Name | Source | Version |
4444
|------|--------|---------|
45-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | ../.. | n/a |
45+
| <a name="module_vpc_ipam_set_cidr"></a> [vpc\_ipam\_set\_cidr](#module\_vpc\_ipam\_set\_cidr) | ../.. | n/a |
46+
| <a name="module_vpc_ipam_set_netmask"></a> [vpc\_ipam\_set\_netmask](#module\_vpc\_ipam\_set\_netmask) | ../.. | n/a |
47+
| <a name="module_vpc_without_ipam"></a> [vpc\_without\_ipam](#module\_vpc\_without\_ipam) | ../.. | n/a |
4648

4749
## Resources
4850

examples/ipam-vpc/main.tf

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ locals {
66
name = "ex-${replace(basename(path.cwd), "_", "-")}"
77
region = "eu-west-1"
88

9-
partition = cidrsubnets(aws_vpc_ipam_preview_next_cidr.this.cidr, 2, 2)
9+
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
10+
preview_partition = cidrsubnets(aws_vpc_ipam_preview_next_cidr.this.cidr, 2, 2)
1011

1112
tags = {
1213
Example = local.name
@@ -19,19 +20,55 @@ locals {
1920
# VPC Module
2021
################################################################################
2122

22-
module "vpc" {
23+
module "vpc_without_ipam" {
2324
source = "../.."
2425

25-
name = local.name
26+
name = "${local.name}-without-ipam"
27+
cidr = "10.0.0.0/16"
2628

27-
private_subnets = cidrsubnets(local.partition[0], 2, 2)
28-
public_subnets = cidrsubnets(local.partition[1], 2, 2)
29+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
30+
public_subnets = ["10.0.11.0/24", "10.0.12.0/24", "10.0.13.0/24"]
31+
32+
tags = local.tags
33+
}
34+
35+
module "vpc_ipam_set_cidr" {
36+
source = "../.."
37+
38+
name = "${local.name}-set-cidr"
2939

3040
ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id
31-
azs = ["${local.region}a", "${local.region}b"]
32-
cidr = aws_vpc_ipam_preview_next_cidr.this.cidr
41+
cidr = "10.0.0.0/16"
42+
azs = local.azs
43+
44+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
45+
public_subnets = ["10.0.11.0/24", "10.0.12.0/24", "10.0.13.0/24"]
46+
47+
tags = local.tags
48+
49+
depends_on = [
50+
aws_vpc_ipam_pool_cidr.this
51+
]
52+
}
53+
54+
module "vpc_ipam_set_netmask" {
55+
source = "../.."
56+
57+
name = "${local.name}-set-netmask"
58+
59+
ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id
60+
ipv4_netmask_length = 28
61+
azs = local.azs
62+
63+
64+
private_subnets = cidrsubnets(local.preview_partition[0], 2, 2, 2)
65+
public_subnets = cidrsubnets(local.preview_partition[1], 2, 2, 2)
3366

3467
tags = local.tags
68+
69+
depends_on = [
70+
aws_vpc_ipam_pool_cidr.this
71+
]
3572
}
3673

3774
################################################################################

0 commit comments

Comments
 (0)