Skip to content

feat: Add secondary IPAM CIDR feature from PR #1074 of the VPC module #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .spacelift/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
version: 1
module_version: 0.2.0

module_version: 0.3.0
13 changes: 11 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
################################################################################
Expand Down
6 changes: 6 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -735,3 +740,4 @@ output "tgw_att_name" {
description = "Name of the TGW attachment"
value = try(aws_ec2_transit_gateway_vpc_attachment.tgw[0].tags["Name"], "")
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't those be in the variables.tf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes you are right.

15 changes: 15 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}