From 90df8526dce726c1e987272561504a9ecd6bc431 Mon Sep 17 00:00:00 2001 From: Sebastian Czech Date: Sat, 4 Jan 2025 16:20:29 +0100 Subject: [PATCH 1/3] Extend variables to have 2 for using IPAM - for IPv4 and IPv6 --- README.md | 3 ++- main.tf | 4 ++-- variables.tf | 10 ++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 97d959771..010f4f9e8 100644 --- a/README.md +++ b/README.md @@ -580,7 +580,8 @@ No modules. | [secondary\_cidr\_blocks](#input\_secondary\_cidr\_blocks) | List of secondary CIDR blocks to associate with the VPC to extend the IP Address pool | `list(string)` | `[]` | no | | [single\_nat\_gateway](#input\_single\_nat\_gateway) | Should be true if you want to provision a single shared NAT Gateway across all of your private networks | `bool` | `false` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | -| [use\_ipam\_pool](#input\_use\_ipam\_pool) | Determines whether IPAM pool is used for CIDR allocation | `bool` | `false` | no | +| [use\_ipv4\_ipam\_pool](#input\_use\_ipv4\_ipam\_pool) | Determines whether IPAM pool is used for IPv4 CIDR allocation | `bool` | `false` | no | +| [use\_ipv6\_ipam\_pool](#input\_use\_ipv6\_ipam\_pool) | Determines whether IPAM pool is used for IPv6 CIDR allocation | `bool` | `false` | no | | [vpc\_flow\_log\_iam\_policy\_name](#input\_vpc\_flow\_log\_iam\_policy\_name) | Name of the IAM policy | `string` | `"vpc-flow-log-to-cloudwatch"` | no | | [vpc\_flow\_log\_iam\_policy\_use\_name\_prefix](#input\_vpc\_flow\_log\_iam\_policy\_use\_name\_prefix) | Determines whether the name of the IAM policy (`vpc_flow_log_iam_policy_name`) is used as a prefix | `bool` | `true` | no | | [vpc\_flow\_log\_iam\_role\_name](#input\_vpc\_flow\_log\_iam\_role\_name) | Name to use on the VPC Flow Log IAM role created | `string` | `"vpc-flow-log-role"` | no | diff --git a/main.tf b/main.tf index 77cba6715..3a2e0dda2 100644 --- a/main.tf +++ b/main.tf @@ -28,11 +28,11 @@ locals { resource "aws_vpc" "this" { count = local.create_vpc ? 1 : 0 - cidr_block = var.use_ipam_pool ? null : var.cidr + cidr_block = var.use_ipv4_ipam_pool ? null : var.cidr ipv4_ipam_pool_id = var.ipv4_ipam_pool_id ipv4_netmask_length = var.ipv4_netmask_length - assign_generated_ipv6_cidr_block = var.enable_ipv6 && !var.use_ipam_pool ? true : null + assign_generated_ipv6_cidr_block = var.enable_ipv6 && !var.use_ipv6_ipam_pool ? true : null ipv6_cidr_block = var.ipv6_cidr ipv6_ipam_pool_id = var.ipv6_ipam_pool_id ipv6_netmask_length = var.ipv6_netmask_length diff --git a/variables.tf b/variables.tf index 095cc8bdf..acf17848b 100644 --- a/variables.tf +++ b/variables.tf @@ -56,8 +56,8 @@ variable "enable_network_address_usage_metrics" { default = null } -variable "use_ipam_pool" { - description = "Determines whether IPAM pool is used for CIDR allocation" +variable "use_ipv4_ipam_pool" { + description = "Determines whether IPAM pool is used for IPv4 CIDR allocation" type = bool default = false } @@ -80,6 +80,12 @@ variable "enable_ipv6" { default = false } +variable "use_ipv6_ipam_pool" { + description = "Determines whether IPAM pool is used for IPv6 CIDR allocation" + type = bool + default = false +} + variable "ipv6_cidr" { description = "(Optional) IPv6 CIDR block to request from an IPAM Pool. Can be set explicitly or derived from IPAM using `ipv6_netmask_length`" type = string From 8bd016db29bd8e0715e7ea72974b0506e1aa6b65 Mon Sep 17 00:00:00 2001 From: Sebastian Czech Date: Sat, 4 Jan 2025 16:20:46 +0100 Subject: [PATCH 2/3] Adjust IPAM example to changes in module --- examples/ipam/main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/ipam/main.tf b/examples/ipam/main.tf index d43851202..9af3beb32 100644 --- a/examples/ipam/main.tf +++ b/examples/ipam/main.tf @@ -28,7 +28,7 @@ module "vpc_ipam_set_netmask" { name = "${local.name}-set-netmask" - use_ipam_pool = true + use_ipv4_ipam_pool = true ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id ipv4_netmask_length = 16 azs = local.azs @@ -48,10 +48,10 @@ module "vpc_ipam_set_cidr" { name = "${local.name}-set-cidr" - use_ipam_pool = true - ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id - cidr = "10.1.0.0/16" - azs = local.azs + use_ipv4_ipam_pool = true + ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id + cidr = "10.1.0.0/16" + azs = local.azs private_subnets = ["10.1.1.0/24", "10.1.2.0/24", "10.1.3.0/24"] public_subnets = ["10.1.11.0/24", "10.1.12.0/24", "10.1.13.0/24"] @@ -65,7 +65,7 @@ module "vpc_ipam_set_cidr" { # name = "${local.name}-ipv6-set-netmask" -# use_ipam_pool = true +# use_ipv4_ipam_pool = true # ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id # ipv6_ipam_pool_id = aws_vpc_ipam_pool.ipv6.id # ipv6_netmask_length = 56 From dcc660a6d2d56e8e914453039b3f2a6e7a70da06 Mon Sep 17 00:00:00 2001 From: Sebastian Czech Date: Wed, 12 Feb 2025 19:24:59 +0100 Subject: [PATCH 3/3] Update README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffe631e3a..5dbf1e85b 100644 --- a/README.md +++ b/README.md @@ -583,7 +583,8 @@ No modules. | [secondary\_cidr\_blocks](#input\_secondary\_cidr\_blocks) | List of secondary CIDR blocks to associate with the VPC to extend the IP Address pool | `list(string)` | `[]` | no | | [single\_nat\_gateway](#input\_single\_nat\_gateway) | Should be true if you want to provision a single shared NAT Gateway across all of your private networks | `bool` | `false` | no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | -| [use\_ipam\_pool](#input\_use\_ipam\_pool) | Determines whether IPAM pool is used for CIDR allocation | `bool` | `false` | no | +| [use\_ipv4\_ipam\_pool](#input\_use\_ipv4\_ipam\_pool) | Determines whether IPAM pool is used for IPv4 CIDR allocation | `bool` | `false` | no | +| [use\_ipv6\_ipam\_pool](#input\_use\_ipv6\_ipam\_pool) | Determines whether IPAM pool is used for IPv6 CIDR allocation | `bool` | `false` | no | | [vpc\_block\_public\_access\_exclusions](#input\_vpc\_block\_public\_access\_exclusions) | A map of VPC block public access exclusions | `map(any)` | `{}` | no | | [vpc\_block\_public\_access\_options](#input\_vpc\_block\_public\_access\_options) | A map of VPC block public access options | `map(string)` | `{}` | no | | [vpc\_flow\_log\_iam\_policy\_name](#input\_vpc\_flow\_log\_iam\_policy\_name) | Name of the IAM policy | `string` | `"vpc-flow-log-to-cloudwatch"` | no |