Skip to content

feat: Add single_nat_gateway_subnet_index to choose NAT Gateway public subnet #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ No modules.
| <a name="input_reuse_nat_ips"></a> [reuse\_nat\_ips](#input\_reuse\_nat\_ips) | Should be true if you don't want EIPs to be created for your NAT Gateways and will instead pass them in via the 'external\_nat\_ip\_ids' variable | `bool` | `false` | no |
| <a name="input_secondary_cidr_blocks"></a> [secondary\_cidr\_blocks](#input\_secondary\_cidr\_blocks) | List of secondary CIDR blocks to associate with the VPC to extend the IP Address pool | `list(string)` | `[]` | no |
| <a name="input_single_nat_gateway"></a> [single\_nat\_gateway](#input\_single\_nat\_gateway) | Should be true if you want to provision a single shared NAT Gateway across all of your private networks | `bool` | `false` | no |
| <a name="input_single_nat_gateway_subnet_index"></a> [single\_nat\_gateway\_subnet\_index](#input\_single\_nat\_gateway\_subnet\_index) | The index of the public subnet used for the NAT Gateway. Only used when `single_nat_gateway` is true | `number` | `0` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
| <a name="input_use_ipam_pool"></a> [use\_ipam\_pool](#input\_use\_ipam\_pool) | Determines whether IPAM pool is used for CIDR allocation | `bool` | `false` | no |
| <a name="input_vpc_flow_log_iam_policy_name"></a> [vpc\_flow\_log\_iam\_policy\_name](#input\_vpc\_flow\_log\_iam\_policy\_name) | Name of the IAM policy | `string` | `"vpc-flow-log-to-cloudwatch"` | no |
Expand Down
2 changes: 2 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module "vpc" {
enable_nat_gateway = true
single_nat_gateway = true

single_nat_gateway_subnet_index = 1

customer_gateways = {
IP1 = {
bgp_asn = 65112
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,14 @@ resource "aws_nat_gateway" "this" {
)
subnet_id = element(
aws_subnet.public[*].id,
var.single_nat_gateway ? 0 : count.index,
var.single_nat_gateway ? var.single_nat_gateway_subnet_index : count.index,
)

tags = merge(
{
"Name" = format(
"Name" = var.single_nat_gateway ? var.name : format(
"${var.name}-%s",
element(var.azs, var.single_nat_gateway ? 0 : count.index),
element(var.azs, count.index),
)
},
var.tags,
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,12 @@ variable "single_nat_gateway" {
default = false
}

variable "single_nat_gateway_subnet_index" {
description = "The index of the public subnet used for the NAT Gateway. Only used when `single_nat_gateway` is true"
type = number
default = 0
}

variable "one_nat_gateway_per_az" {
description = "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`"
type = bool
Expand Down