Skip to content

Commit 2295081

Browse files
drewmullenbryantbiggs
authored andcommitted
ipv6 parameters for vpc
1 parent 0e8d251 commit 2295081

File tree

5 files changed

+79
-10
lines changed

5 files changed

+79
-10
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ No modules.
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 |
458458
| <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 |
459+
| <a name="input_ipv6_cidr"></a> [ipv6\_cidr](#input\_ipv6\_cidr) | (Optional) IPv6 CIDR block to request from an IPAM Pool. Can be set explicitly or derived from IPAM using `ipv6_netmask_length`. | `string` | `null` | no |
460+
| <a name="input_ipv6_ipam_pool_id"></a> [ipv6\_ipam\_pool\_id](#input\_ipv6\_ipam\_pool\_id) | (Optional) IPAM Pool ID for a IPv6 pool. Conflicts with `assign_generated_ipv6_cidr_block`. | `string` | `null` | no |
461+
| <a name="input_ipv6_netmask_length"></a> [ipv6\_netmask\_length](#input\_ipv6\_netmask\_length) | (Optional) Netmask length to request from IPAM Pool. Conflicts with `ipv6_cidr_block`. This can be omitted if IPAM pool as a `allocation_default_netmask_length` set. Valid values: `56`. | `number` | `null` | no |
459462
| <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 |
460463
| <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 |
461464
| <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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To run this example you need to execute:
1111
```bash
1212
$ terraform init
1313
$ terraform plan
14-
$ terraform apply -target=aws_vpc_ipam_preview_next_cidr.this # CIDR pool must exist before assigning CIDR from pool
14+
$ terraform apply -target=aws_vpc_ipam_preview_next_cidr.this -target=aws_vpc_ipam_preview_next_cidr.ipv6 # CIDR pool must exist before assigning CIDR from pool
1515
$ terraform apply
1616
```
1717

@@ -44,15 +44,19 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4444
|------|--------|---------|
4545
| <a name="module_vpc_ipam_set_cidr"></a> [vpc\_ipam\_set\_cidr](#module\_vpc\_ipam\_set\_cidr) | ../.. | n/a |
4646
| <a name="module_vpc_ipam_set_netmask"></a> [vpc\_ipam\_set\_netmask](#module\_vpc\_ipam\_set\_netmask) | ../.. | n/a |
47+
| <a name="module_vpc_ipv6_ipam_set_netmask"></a> [vpc\_ipv6\_ipam\_set\_netmask](#module\_vpc\_ipv6\_ipam\_set\_netmask) | ../.. | n/a |
4748
| <a name="module_vpc_without_ipam"></a> [vpc\_without\_ipam](#module\_vpc\_without\_ipam) | ../.. | n/a |
4849

4950
## Resources
5051

5152
| Name | Type |
5253
|------|------|
5354
| [aws_vpc_ipam.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam) | resource |
55+
| [aws_vpc_ipam_pool.ipv6](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool) | resource |
5456
| [aws_vpc_ipam_pool.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool) | resource |
57+
| [aws_vpc_ipam_pool_cidr.ipv6](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr) | resource |
5558
| [aws_vpc_ipam_pool_cidr.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr) | resource |
59+
| [aws_vpc_ipam_preview_next_cidr.ipv6](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_preview_next_cidr) | resource |
5660
| [aws_vpc_ipam_preview_next_cidr.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_preview_next_cidr) | resource |
5761

5862
## Inputs

examples/ipam-vpc/main.tf

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

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)
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, 2)
11+
ipv6_preview_partition = cidrsubnets(aws_vpc_ipam_preview_next_cidr.ipv6.cidr, 2, 2, 2)
1112

1213
tags = {
1314
Example = local.name
@@ -20,6 +21,7 @@ locals {
2021
# VPC Module
2122
################################################################################
2223

24+
# IPv4
2325
module "vpc_without_ipam" {
2426
source = "../.."
2527

@@ -60,7 +62,6 @@ module "vpc_ipam_set_netmask" {
6062
ipv4_netmask_length = 28
6163
azs = local.azs
6264

63-
6465
private_subnets = cidrsubnets(local.preview_partition[0], 2, 2, 2)
6566
public_subnets = cidrsubnets(local.preview_partition[1], 2, 2, 2)
6667

@@ -71,6 +72,26 @@ module "vpc_ipam_set_netmask" {
7172
]
7273
}
7374

75+
# IPv6
76+
module "vpc_ipv6_ipam_set_netmask" {
77+
source = "../.."
78+
79+
name = "${local.name}-ipv6-set-netmask"
80+
81+
ipv6_ipam_pool_id = aws_vpc_ipam_pool.ipv6.id
82+
ipv6_netmask_length = 60
83+
azs = local.azs
84+
85+
private_subnets = cidrsubnets(local.ipv6_preview_partition[0], 2, 2, 2)
86+
public_subnets = cidrsubnets(local.ipv6_preview_partition[1], 2, 2, 2)
87+
88+
tags = local.tags
89+
90+
depends_on = [
91+
aws_vpc_ipam_pool_cidr.ipv6
92+
]
93+
}
94+
7495
################################################################################
7596
# Supporting Resources
7697
################################################################################
@@ -115,3 +136,22 @@ resource "aws_vpc_ipam_preview_next_cidr" "this" {
115136
aws_vpc_ipam_pool_cidr.this
116137
]
117138
}
139+
140+
resource "aws_vpc_ipam_pool" "ipv6" {
141+
address_family = "ipv6"
142+
ipam_scope_id = aws_vpc_ipam.this.private_default_scope_id
143+
locale = local.region
144+
allocation_default_netmask_length = 56
145+
}
146+
147+
resource "aws_vpc_ipam_pool_cidr" "ipv6" {
148+
ipam_pool_id = aws_vpc_ipam_pool.ipv6.id
149+
}
150+
151+
resource "aws_vpc_ipam_preview_next_cidr" "ipv6" {
152+
ipam_pool_id = aws_vpc_ipam_pool.ipv6.id
153+
154+
depends_on = [
155+
aws_vpc_ipam_pool_cidr.ipv6
156+
]
157+
}

main.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ resource "aws_vpc" "this" {
2424
ipv4_ipam_pool_id = var.ipv4_ipam_pool_id
2525
ipv4_netmask_length = var.ipv4_netmask_length
2626

27-
instance_tenancy = var.instance_tenancy
28-
enable_dns_hostnames = var.enable_dns_hostnames
29-
enable_dns_support = var.enable_dns_support
30-
enable_classiclink = null # https://github.com/hashicorp/terraform/issues/31730
31-
enable_classiclink_dns_support = null # https://github.com/hashicorp/terraform/issues/31730
32-
assign_generated_ipv6_cidr_block = var.enable_ipv6
27+
instance_tenancy = var.instance_tenancy
28+
enable_dns_hostnames = var.enable_dns_hostnames
29+
enable_dns_support = var.enable_dns_support
30+
enable_classiclink = null # https://github.com/hashicorp/terraform/issues/31730
31+
enable_classiclink_dns_support = null # https://github.com/hashicorp/terraform/issues/31730
32+
33+
assign_generated_ipv6_cidr_block = var.enable_ipv6 && var.ipv6_ipam_pool_id == "" ? true : null
34+
ipv6_cidr_block = var.ipv6_cidr
35+
ipv6_ipam_pool_id = var.ipv6_ipam_pool_id
36+
ipv6_netmask_length = var.ipv6_netmask_length
3337

3438
tags = merge(
3539
{ "Name" = var.name },

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,24 @@ variable "ipv4_netmask_length" {
12021202
default = null
12031203
}
12041204

1205+
variable "ipv6_cidr" {
1206+
description = "(Optional) IPv6 CIDR block to request from an IPAM Pool. Can be set explicitly or derived from IPAM using `ipv6_netmask_length`."
1207+
type = string
1208+
default = null
1209+
}
1210+
1211+
variable "ipv6_ipam_pool_id" {
1212+
description = "(Optional) IPAM Pool ID for a IPv6 pool. Conflicts with `assign_generated_ipv6_cidr_block`."
1213+
type = string
1214+
default = null
1215+
}
1216+
1217+
variable "ipv6_netmask_length" {
1218+
description = "(Optional) Netmask length to request from IPAM Pool. Conflicts with `ipv6_cidr_block`. This can be omitted if IPAM pool as a `allocation_default_netmask_length` set. Valid values: `56`."
1219+
type = number
1220+
default = null
1221+
}
1222+
12051223
variable "putin_khuylo" {
12061224
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
12071225
type = bool

0 commit comments

Comments
 (0)