Skip to content

Commit 0b3cbe6

Browse files
authored
feat: Add option to create/delete NAT Gateway route for private route tables
1 parent 12caf80 commit 0b3cbe6

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ No modules.
531531
| <a name="input_private_subnet_ipv6_prefixes"></a> [private\_subnet\_ipv6\_prefixes](#input\_private\_subnet\_ipv6\_prefixes) | Assigns IPv6 private subnet id based on the Amazon provided /56 prefix base 10 integer (0-256). Must be of equal length to the corresponding IPv4 subnet list | `list(string)` | `[]` | no |
532532
| <a name="input_private_subnet_names"></a> [private\_subnet\_names](#input\_private\_subnet\_names) | Explicit values to use in the Name tag on private subnets. If empty, Name tags are generated | `list(string)` | `[]` | no |
533533
| <a name="input_private_subnet_private_dns_hostname_type_on_launch"></a> [private\_subnet\_private\_dns\_hostname\_type\_on\_launch](#input\_private\_subnet\_private\_dns\_hostname\_type\_on\_launch) | The type of hostnames to assign to instances in the subnet at launch. For IPv6-only subnets, an instance DNS name must be based on the instance ID. For dual-stack and IPv4-only subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID. Valid values: `ip-name`, `resource-name` | `string` | `null` | no |
534-
| <a name="input_private_subnet_suffix"></a> [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Suffix to append to private subnets name | `string` | `"private"` | no |
534+
| <a name="input_private_subnet_suffix"></a> [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Controls if a nat gateway route should be created to give internet access to the private subnets | `bool` | `true` | no |
535+
| <a name="input_create_private_nat_gateway_route"></a> [private\_subnet\_suffix](#input\_create\_private\_nat\_gateway\_route) | Suffix to append to private subnets name | `string` | `"private"` | no |
535536
| <a name="input_private_subnet_tags"></a> [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no |
536537
| <a name="input_private_subnet_tags_per_az"></a> [private\_subnet\_tags\_per\_az](#input\_private\_subnet\_tags\_per\_az) | Additional tags for the private subnets where the primary key is the AZ | `map(map(string))` | `{}` | no |
537538
| <a name="input_private_subnets"></a> [private\_subnets](#input\_private\_subnets) | A list of private subnets inside the VPC | `list(string)` | `[]` | no |

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ resource "aws_nat_gateway" "this" {
11021102
}
11031103

11041104
resource "aws_route" "private_nat_gateway" {
1105-
count = local.create_vpc && var.enable_nat_gateway ? local.nat_gateway_count : 0
1105+
count = local.create_vpc && var.enable_nat_gateway && var.create_private_nat_gateway_route ? local.nat_gateway_count : 0
11061106

11071107
route_table_id = element(aws_route_table.private[*].id, count.index)
11081108
destination_cidr_block = var.nat_gateway_destination_cidr_block

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ variable "private_subnet_suffix" {
372372
default = "private"
373373
}
374374

375+
variable "create_private_nat_gateway_route" {
376+
description = "Controls if a nat gateway route should be created to give internet access to the private subnets"
377+
type = bool
378+
default = true
379+
}
380+
375381
variable "private_subnet_tags" {
376382
description = "Additional tags for the private subnets"
377383
type = map(string)

0 commit comments

Comments
 (0)