Skip to content

Commit ba1e12e

Browse files
author
balvinder
committed
feat: adding support for regional nat gateway
1 parent b30551b commit ba1e12e

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ Full contributing [guidelines are covered here](.github/contributing.md).
241241
| Name | Version |
242242
|------|---------|
243243
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
244-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
244+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.24.0 |
245245

246246
## Providers
247247

248248
| Name | Version |
249249
|------|---------|
250-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
250+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.24.0 |
251251

252252
## Modules
253253

@@ -272,6 +272,7 @@ No modules.
272272
| [aws_iam_role.vpc_flow_log_cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
273273
| [aws_iam_role_policy_attachment.vpc_flow_log_cloudwatch](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
274274
| [aws_internet_gateway.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway) | resource |
275+
| [aws_nat_gateway.regional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/nat_gateway) | resource |
275276
| [aws_nat_gateway.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/nat_gateway) | resource |
276277
| [aws_network_acl.database](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_acl) | resource |
277278
| [aws_network_acl.elasticache](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/network_acl) | resource |
@@ -487,6 +488,7 @@ No modules.
487488
| <a name="input_map_public_ip_on_launch"></a> [map\_public\_ip\_on\_launch](#input\_map\_public\_ip\_on\_launch) | Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is `false` | `bool` | `false` | no |
488489
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | `""` | no |
489490
| <a name="input_nat_eip_tags"></a> [nat\_eip\_tags](#input\_nat\_eip\_tags) | Additional tags for the NAT EIP | `map(string)` | `{}` | no |
491+
| <a name="input_nat_gateway_connectivity_type"></a> [nat\_gateway\_connectivity\_type](#input\_nat\_gateway\_connectivity\_type) | Connectivity type for the NAT Gateway. Valid values are:<br/>- 'zonal' (default): Traditional AZ-specific NAT gateways that require public subnets<br/>- 'regional': A single NAT Gateway that automatically scales across all AZs (does not require public subnets)<br/><br/>Regional NAT Gateway support requires Terraform AWS provider >= 6.24.0.<br/>When using 'regional' mode, only one NAT Gateway is created for the entire VPC. | `string` | `"zonal"` | no |
490492
| <a name="input_nat_gateway_destination_cidr_block"></a> [nat\_gateway\_destination\_cidr\_block](#input\_nat\_gateway\_destination\_cidr\_block) | Used to pass a custom destination route for private NAT Gateway. If not specified, the default 0.0.0.0/0 is used as a destination route | `string` | `"0.0.0.0/0"` | no |
491493
| <a name="input_nat_gateway_tags"></a> [nat\_gateway\_tags](#input\_nat\_gateway\_tags) | Additional tags for the NAT gateways | `map(string)` | `{}` | no |
492494
| <a name="input_one_nat_gateway_per_az"></a> [one\_nat\_gateway\_per\_az](#input\_one\_nat\_gateway\_per\_az) | Should be true if you want only one NAT Gateway per availability zone. Requires `var.azs` to be set, and the number of `public_subnets` created to be greater than or equal to the number of availability zones specified in `var.azs` | `bool` | `false` | no |

examples/regional-nat/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,3 @@ After applying this configuration, you can see:
8484

8585
- [AWS Regional NAT Gateway Documentation](https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateways-regional.html)
8686
- [AWS Blog: Introducing Amazon VPC Regional NAT Gateway](https://aws.amazon.com/blogs/networking-and-content-delivery/introducing-amazon-vpc-regional-nat-gateway/)
87-

examples/regional-nat/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ provider "aws" {
99
data "aws_availability_zones" "available" {}
1010

1111
locals {
12-
name = "ex-${basename(path.cwd)}"
12+
name = "ex-${basename(path.cwd)}"
1313

1414
vpc_cidr = "10.0.0.0/16"
1515
azs = slice(data.aws_availability_zones.available.names, 0, 3)
1616

1717
tags = {
18-
Example = local.name
18+
Example = local.name
1919
}
2020
}
2121

2222
module "vpc" {
2323
source = "../../"
24-
name = local.name
25-
cidr = local.vpc_cidr
24+
name = local.name
25+
cidr = local.vpc_cidr
2626

27-
azs = local.azs
28-
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
29-
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 4)]
27+
azs = local.azs
28+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
29+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 4)]
3030
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 8)]
3131

3232
enable_dns_hostnames = true
@@ -36,5 +36,5 @@ module "vpc" {
3636
# Requires Terraform AWS provider >= 6.24.0
3737
enable_nat_gateway = true
3838
nat_gateway_connectivity_type = "regional"
39-
tags = local.tags
39+
tags = local.tags
4040
}

examples/regional-nat/outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,3 @@ output "igw_id" {
7373
description = "The ID of the Internet Gateway"
7474
value = module.vpc.igw_id
7575
}
76-

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ resource "aws_route_table" "private" {
337337
"Name" = local.nat_gateway_is_regional ? format(
338338
"${var.name}-${var.private_subnet_suffix}-%s",
339339
element(var.azs, count.index),
340-
) : var.single_nat_gateway ? "${var.name}-${var.private_subnet_suffix}" : format(
340+
) : var.single_nat_gateway ? "${var.name}-${var.private_subnet_suffix}" : format(
341341
"${var.name}-${var.private_subnet_suffix}-%s",
342342
element(var.azs, count.index),
343343
)
@@ -1208,8 +1208,8 @@ resource "aws_route" "private_ipv6_egress" {
12081208

12091209
locals {
12101210
nat_gateway_is_regional = var.nat_gateway_connectivity_type == "regional"
1211-
nat_gateway_count = local.nat_gateway_is_regional ? 1 : var.single_nat_gateway ? 1 : var.one_nat_gateway_per_az ? length(var.azs) : local.max_subnet_length
1212-
nat_gateway_ips = var.reuse_nat_ips ? var.external_nat_ip_ids : aws_eip.nat[*].id
1211+
nat_gateway_count = local.nat_gateway_is_regional ? 1 : var.single_nat_gateway ? 1 : var.one_nat_gateway_per_az ? length(var.azs) : local.max_subnet_length
1212+
nat_gateway_ips = var.reuse_nat_ips ? var.external_nat_ip_ids : aws_eip.nat[*].id
12131213
}
12141214

12151215
resource "aws_eip" "nat" {

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ variable "nat_gateway_connectivity_type" {
12391239
Connectivity type for the NAT Gateway. Valid values are:
12401240
- 'zonal' (default): Traditional AZ-specific NAT gateways that require public subnets
12411241
- 'regional': A single NAT Gateway that automatically scales across all AZs (does not require public subnets)
1242-
1242+
12431243
Regional NAT Gateway support requires Terraform AWS provider >= 6.24.0.
12441244
When using 'regional' mode, only one NAT Gateway is created for the entire VPC.
12451245
EOT

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ module "wrapper" {
232232
map_public_ip_on_launch = try(each.value.map_public_ip_on_launch, var.defaults.map_public_ip_on_launch, false)
233233
name = try(each.value.name, var.defaults.name, "")
234234
nat_eip_tags = try(each.value.nat_eip_tags, var.defaults.nat_eip_tags, {})
235+
nat_gateway_connectivity_type = try(each.value.nat_gateway_connectivity_type, var.defaults.nat_gateway_connectivity_type, "zonal")
235236
nat_gateway_destination_cidr_block = try(each.value.nat_gateway_destination_cidr_block, var.defaults.nat_gateway_destination_cidr_block, "0.0.0.0/0")
236237
nat_gateway_tags = try(each.value.nat_gateway_tags, var.defaults.nat_gateway_tags, {})
237238
one_nat_gateway_per_az = try(each.value.one_nat_gateway_per_az, var.defaults.one_nat_gateway_per_az, false)

wrappers/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 6.0"
7+
version = ">= 6.24.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)