Skip to content

Commit f0e8c4f

Browse files
Add multi_az_private_rtb option
1 parent 3cb319c commit f0e8c4f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

_variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ variable "multi_nat" {
3636
description = "Number of NAT Instances, 'true' will yield one per AZ while 'false' creates one NAT"
3737
}
3838

39+
variable "multi_az_private_rtb" {
40+
type = bool
41+
default = false
42+
description = "Create multiple private route tables, one per AZ"
43+
}
44+
45+
3946
variable "newbits" {
4047
type = number
4148
default = 5

subnet-private.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "aws_subnet" "private" {
2626
}
2727

2828
resource "aws_route_table" "private" {
29-
count = var.nat && var.multi_nat ? (
29+
count = var.nat && var.multi_nat || var.nat && var.multi_az_private_rtb ? (
3030
length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
3131
) : 1
3232
vpc_id = aws_vpc.default.id
@@ -42,13 +42,13 @@ resource "aws_route_table" "private" {
4242
}
4343

4444
resource "aws_route" "nat_route" {
45-
count = var.nat && var.multi_nat ? (
45+
count = var.nat && var.multi_nat || var.nat && var.multi_az_private_rtb ? (
4646
length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
4747
) : (var.nat ? 1 : 0)
4848

4949
route_table_id = aws_route_table.private[count.index].id
5050
destination_cidr_block = "0.0.0.0/0"
51-
nat_gateway_id = aws_nat_gateway.nat_gw[count.index].id
51+
nat_gateway_id = var.multi_az_private_rtb ? aws_nat_gateway.nat_gw[count.index].id : aws_nat_gateway.nat_gw[0].id
5252

5353
lifecycle {
5454
create_before_destroy = true
@@ -60,7 +60,7 @@ resource "aws_route" "nat_route" {
6060
resource "aws_route_table_association" "private" {
6161
count = length(aws_subnet.private)
6262
subnet_id = aws_subnet.private[count.index].id
63-
route_table_id = var.multi_nat ? aws_route_table.private[count.index].id : aws_route_table.private[0].id
63+
route_table_id = var.multi_nat || var.multi_az_private_rtb ? aws_route_table.private[count.index].id : aws_route_table.private[0].id
6464

6565
lifecycle {
6666
ignore_changes = [subnet_id]

0 commit comments

Comments
 (0)