From 832fe9856ead25db1fa0dbc680267a0b486282d8 Mon Sep 17 00:00:00 2001 From: Marvin Bertram Date: Mon, 2 Sep 2024 20:27:52 +0200 Subject: [PATCH 1/3] Add secondary IPAM CIDR feature from PR #1074 of the VPC module --- main.tf | 13 +++++++++++-- outputs.tf | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 106b96cf0..301900d18 100644 --- a/main.tf +++ b/main.tf @@ -17,8 +17,7 @@ locals { ) # Use `local.vpc_id` to give a hint to Terraform that subnets should be deleted before secondary CIDR blocks can be free! - vpc_id = try(aws_vpc_ipv4_cidr_block_association.this[0].vpc_id, aws_vpc.this[0].id, "") - + vpc_id = try(aws_vpc_ipv4_cidr_block_association.this[0].vpc_id, aws_vpc_ipv4_cidr_block_association.ipam[0].vpc_id, aws_vpc.this[0].id, "") create_vpc = var.create_vpc && var.putin_khuylo } @@ -60,6 +59,16 @@ resource "aws_vpc_ipv4_cidr_block_association" "this" { cidr_block = element(var.secondary_cidr_blocks, count.index) } +resource "aws_vpc_ipv4_cidr_block_association" "ipam" { + count = local.create_vpc && length(var.secondary_ipam_pool_ids) > 0 ? length(var.secondary_ipam_pool_ids) : 0 + + # Do not turn this into `local.vpc_id` + vpc_id = aws_vpc.this[0].id + + ipv4_ipam_pool_id = element(var.secondary_ipam_pool_ids, count.index) + ipv4_netmask_length = element(var.secondary_ipam_pool_netmask, count.index) +} + ################################################################################ # DHCP Options Set ################################################################################ diff --git a/outputs.tf b/outputs.tf index 301a64f30..e8e40b6e2 100644 --- a/outputs.tf +++ b/outputs.tf @@ -74,6 +74,11 @@ output "vpc_secondary_cidr_blocks" { value = compact(aws_vpc_ipv4_cidr_block_association.this[*].cidr_block) } +output "vpc_secondary_cidr_blocks_ipam" { + description = "List of secondary CIDR blocks allocated from the IPAM for the VPC" + value = compact(aws_vpc_ipv4_cidr_block_association.ipam[*].cidr_block) +} + output "vpc_owner_id" { description = "The ID of the AWS account that owns the VPC" value = try(aws_vpc.this[0].owner_id, null) @@ -715,3 +720,18 @@ output "tgw_att_name" { description = "Name of the TGW attachment" value = try(aws_ec2_transit_gateway_vpc_attachment.tgw[0].tags["Name"], "") } + +################################################################################ +# Secondary IAPM +################################################################################ + +variable "secondary_ipam_pool_ids" { + description = "List of secondary IPAM pool IDs to associate with the VPC to extend the IP Address pool" + type = list(string) + default = [] +} + +variable "secondary_ipam_pool_netmask" { + description = "List of secondary IPAM pool netmasks to associate with the VPC to extend the IP Address pool" + type = list(number) +} From 6f690cb321636f152ea2b888005f31b8721fd266 Mon Sep 17 00:00:00 2001 From: Marvin Bertram Date: Tue, 3 Sep 2024 16:33:47 +0200 Subject: [PATCH 2/3] Update version --- .spacelift/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.spacelift/config.yml b/.spacelift/config.yml index bc464466c..b7d20b93d 100644 --- a/.spacelift/config.yml +++ b/.spacelift/config.yml @@ -1,2 +1,2 @@ version: 1 -module_version: 0.1.0 +module_version: 0.3.0 From 01b97e11bc15b5655b5423e01d2da20741b36415 Mon Sep 17 00:00:00 2001 From: Marvin Bertram Date: Tue, 3 Sep 2024 17:08:37 +0200 Subject: [PATCH 3/3] Move variables to variables.tf --- outputs.tf | 14 -------------- variables.tf | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/outputs.tf b/outputs.tf index e8e40b6e2..d159e567d 100644 --- a/outputs.tf +++ b/outputs.tf @@ -721,17 +721,3 @@ output "tgw_att_name" { value = try(aws_ec2_transit_gateway_vpc_attachment.tgw[0].tags["Name"], "") } -################################################################################ -# Secondary IAPM -################################################################################ - -variable "secondary_ipam_pool_ids" { - description = "List of secondary IPAM pool IDs to associate with the VPC to extend the IP Address pool" - type = list(string) - default = [] -} - -variable "secondary_ipam_pool_netmask" { - description = "List of secondary IPAM pool netmasks to associate with the VPC to extend the IP Address pool" - type = list(number) -} diff --git a/variables.tf b/variables.tf index bfd56e37d..1bc60c030 100644 --- a/variables.tf +++ b/variables.tf @@ -1835,3 +1835,18 @@ variable "tgw_acl_tags" { type = map(string) default = {} } + +################################################################################ +# Secondary IPAM +################################################################################ + +variable "secondary_ipam_pool_ids" { + description = "List of secondary IPAM pool IDs to associate with the VPC to extend the IP Address pool" + type = list(string) + default = [] +} + +variable "secondary_ipam_pool_netmask" { + description = "List of secondary IPAM pool netmasks to associate with the VPC to extend the IP Address pool" + type = list(number) +}