Resource: aws_nat_gateway

Provides a resource to create a VPC NAT Gateway.

Example Usage

Public NAT

resource "aws_nat_gateway" "example" {
  allocation_id = aws_eip.example.id
  subnet_id     = aws_subnet.example.id

  tags = {
    Name = "gw NAT"
  }

  # To ensure proper ordering, it is recommended to add an explicit dependency
  # on the Internet Gateway for the VPC.
  depends_on = [aws_internet_gateway.example]
}

Public NAT with Secondary Private IP Addresses

resource "aws_nat_gateway" "example" {
  allocation_id                  = aws_eip.example.id
  subnet_id                      = aws_subnet.example.id
  secondary_allocation_ids       = [aws_eip.secondary.id]
  secondary_private_ip_addresses = ["10.0.1.5"]
}

Private NAT

resource "aws_nat_gateway" "example" {
  connectivity_type = "private"
  subnet_id         = aws_subnet.example.id
}

Private NAT with Secondary Private IP Addresses

resource "aws_nat_gateway" "example" {
  connectivity_type                  = "private"
  subnet_id                          = aws_subnet.example.id
  secondary_private_ip_address_count = 7
}

Argument Reference

This resource supports the following arguments:

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import NAT Gateways using the id. For example:

import {
  to = aws_nat_gateway.private_gw
  id = "nat-05dba92075d71c408"
}

Using terraform import, import NAT Gateways using the id. For example:

% terraform import aws_nat_gateway.private_gw nat-05dba92075d71c408