Skip to content

Commit bd2e9c3

Browse files
committed
add AWS VPC IPAM resources and update load balancer configuration for IPAM pools
1 parent fc0a589 commit bd2e9c3

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ No modules.
411411
| <a name="input_idle_timeout"></a> [idle\_timeout](#input\_idle\_timeout) | The time in seconds that the connection is allowed to be idle. Only valid for Load Balancers of type `application`. Default: `60` | `number` | `null` | no |
412412
| <a name="input_internal"></a> [internal](#input\_internal) | If true, the LB will be internal. Defaults to `false` | `bool` | `null` | no |
413413
| <a name="input_ip_address_type"></a> [ip\_address\_type](#input\_ip\_address\_type) | The type of IP addresses used by the subnets for your load balancer. The possible values are `ipv4` and `dualstack` | `string` | `null` | no |
414+
| <a name="input_ipam_pools"></a> [ipam\_pools](#input\_ipam\_pools) | The IPAM pools to use with the load balancer | `map(string)` | `{}` | no |
414415
| <a name="input_listeners"></a> [listeners](#input\_listeners) | Map of listener configurations to create | `any` | `{}` | no |
415416
| <a name="input_load_balancer_type"></a> [load\_balancer\_type](#input\_load\_balancer\_type) | The type of load balancer to create. Possible values are `application`, `gateway`, or `network`. The default value is `application` | `string` | `"application"` | no |
416417
| <a name="input_name"></a> [name](#input\_name) | The name of the LB. This name must be unique within your AWS account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen | `string` | `null` | no |

examples/complete-alb/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Note that this example may create resources which cost money. Run `terraform des
5454
| [aws_cognito_user_pool_domain.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool_domain) | resource |
5555
| [aws_instance.other](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource |
5656
| [aws_instance.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource |
57+
| [aws_vpc_ipam.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam) | resource |
58+
| [aws_vpc_ipam_pool.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool) | resource |
59+
| [aws_vpc_ipam_pool_cidr.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_ipam_pool_cidr) | resource |
5760
| [null_resource.download_package](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
5861
| [random_string.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
5962
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |

examples/complete-alb/main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ module "alb" {
6767
prefix = "connection-logs"
6868
}
6969

70+
ipam_pools = {
71+
ipv4_ipam_pool_id = aws_vpc_ipam_pool.this.id
72+
}
73+
7074
client_keep_alive = 7200
7175

7276
listeners = {
@@ -660,3 +664,28 @@ module "log_bucket" {
660664

661665
tags = local.tags
662666
}
667+
668+
##################################################################
669+
# AWS VPC IPAM
670+
##################################################################
671+
672+
resource "aws_vpc_ipam" "this" {
673+
operating_regions {
674+
region_name = local.region
675+
}
676+
}
677+
678+
resource "aws_vpc_ipam_pool" "this" {
679+
address_family = "ipv4"
680+
ipam_scope_id = aws_vpc_ipam.this.public_default_scope_id
681+
locale = local.region
682+
allocation_default_netmask_length = 30
683+
684+
public_ip_source = "amazon"
685+
aws_service = "ec2"
686+
}
687+
688+
resource "aws_vpc_ipam_pool_cidr" "this" {
689+
ipam_pool_id = aws_vpc_ipam_pool.this.id
690+
netmask_length = 30
691+
}

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ resource "aws_lb" "this" {
3131
}
3232
}
3333

34+
dynamic "ipam_pools" {
35+
for_each = length(var.ipam_pools) > 0 ? [var.ipam_pools] : []
36+
content {
37+
ipv4_ipam_pool_id = ipam_pools.value.ipv4_ipam_pool_id
38+
}
39+
}
40+
3441
client_keep_alive = var.client_keep_alive
3542
customer_owned_ipv4_pool = var.customer_owned_ipv4_pool
3643
desync_mitigation_mode = var.desync_mitigation_mode

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ variable "connection_logs" {
2626
default = {}
2727
}
2828

29+
variable "ipam_pools" {
30+
description = "The IPAM pools to use with the load balancer"
31+
type = map(string)
32+
default = {}
33+
}
34+
2935
variable "client_keep_alive" {
3036
description = "Client keep alive value in seconds. The valid range is 60-604800 seconds. The default is 3600 seconds."
3137
type = number

0 commit comments

Comments
 (0)