Skip to content

Too many NAT gateways created #117

@sc250024

Description

@sc250024

Not sure whether to file this under "feature", or "bug"; I suppose it depends on how a person views subnetting in AWS VPC.

Basically, I have 6 private subnets calculated from a base /16 prefix, and being created in the eu-west-1 region as follows:

    private_subnets = [
        "${cidrsubnet(var.cidr_block, 7, 7)}",
        "${cidrsubnet(var.cidr_block, 7, 8)}",
        "${cidrsubnet(var.cidr_block, 7, 9)}",
        "${cidrsubnet(var.cidr_block, 4, 13)}",
        "${cidrsubnet(var.cidr_block, 4, 14)}",
        "${cidrsubnet(var.cidr_block, 4, 15)}",
    ]

In the module definition, I have also specified to use all 3 availability zones eu-west-1a, eu-west-1b, and eu-west-1c. The module then generates 6 NAT gateways that look like this:

  + module.vpc.aws_route.private_nat_gateway[X]
      id:                                     <computed>
      destination_cidr_block:                 "0.0.0.0/0"
      destination_prefix_list_id:             <computed>
      egress_only_gateway_id:                 <computed>
      gateway_id:                             <computed>
      instance_id:                            <computed>
      instance_owner_id:                      <computed>
      nat_gateway_id:                         "${element(aws_nat_gateway.this.*.id, count.index)}"
      network_interface_id:                   <computed>
      origin:                                 <computed>
      route_table_id:                         "${element(aws_route_table.private.*.id, count.index)}"
      state:                                  <computed>

My question: isn't one NAT gateway per private subnet a bit excessive? If the number of availability zones is defined by ${length(var.azs)}, then shouldn't only ${length(var.azs)} number of NAT gateways be created, and added to the route tables?

This is especially true as a person's user account is charged per hour that each NAT gateway instance is running: https://aws.amazon.com/vpc/pricing/#natgatewaypricing

My info:
Terraform v0.11.7
Provider.aws v1.14.0
Module version: 1.30.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions