From 0b3cbe6041b819c4f3549b79075a6db696a90805 Mon Sep 17 00:00:00 2001 From: Alex Poliukh Date: Sun, 3 Nov 2024 06:32:40 +0200 Subject: [PATCH 1/2] feat: Add option to create/delete NAT Gateway route for private route tables --- README.md | 3 ++- main.tf | 2 +- variables.tf | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62a00f119..1d52c600f 100644 --- a/README.md +++ b/README.md @@ -531,7 +531,8 @@ No modules. | [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 | | [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 | | [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 | -| [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Suffix to append to private subnets name | `string` | `"private"` | no | +| [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 | +| [private\_subnet\_suffix](#input\_create\_private\_nat\_gateway\_route) | Suffix to append to private subnets name | `string` | `"private"` | no | | [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no | | [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 | | [private\_subnets](#input\_private\_subnets) | A list of private subnets inside the VPC | `list(string)` | `[]` | no | diff --git a/main.tf b/main.tf index 05b4f5e22..77cba6715 100644 --- a/main.tf +++ b/main.tf @@ -1102,7 +1102,7 @@ resource "aws_nat_gateway" "this" { } resource "aws_route" "private_nat_gateway" { - count = local.create_vpc && var.enable_nat_gateway ? local.nat_gateway_count : 0 + count = local.create_vpc && var.enable_nat_gateway && var.create_private_nat_gateway_route ? local.nat_gateway_count : 0 route_table_id = element(aws_route_table.private[*].id, count.index) destination_cidr_block = var.nat_gateway_destination_cidr_block diff --git a/variables.tf b/variables.tf index 8bfae5164..39521ae15 100644 --- a/variables.tf +++ b/variables.tf @@ -372,6 +372,12 @@ variable "private_subnet_suffix" { default = "private" } +variable "create_private_nat_gateway_route" { + description = "Controls if a nat gateway route should be created to give internet access to the private subnets" + type = bool + default = true +} + variable "private_subnet_tags" { description = "Additional tags for the private subnets" type = map(string) From 4e4e4203ac3f14800bffffb644de0a66c33879c4 Mon Sep 17 00:00:00 2001 From: Alex Poliukh Date: Sun, 3 Nov 2024 06:36:47 +0200 Subject: [PATCH 2/2] feat: Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d52c600f..ac08bbbe7 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,7 @@ No modules. | [create\_igw](#input\_create\_igw) | Controls if an Internet Gateway is created for public subnets and the related routes that connect them | `bool` | `true` | no | | [create\_multiple\_intra\_route\_tables](#input\_create\_multiple\_intra\_route\_tables) | Indicates whether to create a separate route table for each intra subnet. Default: `false` | `bool` | `false` | no | | [create\_multiple\_public\_route\_tables](#input\_create\_multiple\_public\_route\_tables) | Indicates whether to create a separate route table for each public subnet. Default: `false` | `bool` | `false` | no | +| [create\_private\_nat\_gateway\_route](#input\_create\_private\_nat\_gateway\_route) | Controls if a nat gateway route should be created to give internet access to the private subnets | `bool` | `true` | no | | [create\_redshift\_subnet\_group](#input\_create\_redshift\_subnet\_group) | Controls if redshift subnet group should be created | `bool` | `true` | no | | [create\_redshift\_subnet\_route\_table](#input\_create\_redshift\_subnet\_route\_table) | Controls if separate route table for redshift should be created | `bool` | `false` | no | | [create\_vpc](#input\_create\_vpc) | Controls if VPC should be created (it affects almost all resources) | `bool` | `true` | no | @@ -531,8 +532,7 @@ No modules. | [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 | | [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 | | [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 | -| [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 | -| [private\_subnet\_suffix](#input\_create\_private\_nat\_gateway\_route) | Suffix to append to private subnets name | `string` | `"private"` | no | +| [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Suffix to append to private subnets name | `string` | `"private"` | no | | [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no | | [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 | | [private\_subnets](#input\_private\_subnets) | A list of private subnets inside the VPC | `list(string)` | `[]` | no |