Skip to main content

Palo Alto Networks NAT Gateway Set Module for AWS

A Terraform module for deploying a NAT Gateway set in AWS cloud. The "set" means that the module will create an identical/similar NAT Gateway in each specified Availability Zone.

GitHub Logo Terraform Logo

Usage

module "vpc" {
source = "../../modules/vpc"

name = var.name
cidr_block = var.vpc_cidr_block
secondary_cidr_blocks = var.vpc_secondary_cidr_blocks
global_tags = var.global_tags
vpc_tags = var.vpc_tags
security_groups = var.security_groups
}

module "subnet_sets" {
source = "../../modules/subnet_set"

for_each = toset(distinct([for _, v in var.subnets : v.set]))

name = each.key
cidrs = { for k, v in var.subnets : k => v if v.set == each.key }
vpc_id = module.vpc.id
}

module "nat_gateway_set" {
source = "../../modules/nat_gateway_set"

subnets = module.subnet_sets["natgw-1"].subnets
}

Reference

Requirements

NameVersion
terraform>= 1.0.0, < 2.0.0
aws~> 5.17

Providers

NameVersion
aws~> 5.17

Modules

No modules.

Resources

NameType
aws_eip.thisresource
aws_nat_gateway.thisresource
aws_eip.thisdata source
aws_nat_gateway.thisdata source

Inputs

NameDescriptionTypeDefaultRequired
create_eipIf false, does not create a new Elastic IP, but instead reads a pre-existing one. This input is ignored if create_nat_gateway is false.booltrueno
create_nat_gatewayIf false, does not create a new NAT Gateway, but instead reads a pre-existing one.booltrueno
eip_domainIndicates if this EIP is for use in VPCstring"vpc"no
eip_tagsn/amap(string){}no
eipsOptional map of Elastic IP attributes. Each key is an Availability Zone name, for example "us-east-1b". Each entry has optional attributes name, public_ip, id.
These are mainly useful to select a pre-existing Elastic IP when create_eip is false. Example:eips = {
"us-east-1a" = { id = aws_eip.a.id }
"us-east-1b" = { id = aws_eip.b.id }
}The name attribute can be used both for selecting the pre-existing Elastic IP, or for customizing a newly created Elastic IP:eips = {
"us-east-1a" = { name = "Alice" }
"us-east-1b" = { name = "Bob" }
}
map{}no
global_tagsn/amap(string){}no
nat_gateway_namesA map, where each key is an Availability Zone name, for example "us-east-1b". Each value in the map is a custom name of a NAT Gateway in that Availability Zone.
The name is kept in an AWS standard Name tag.
Example:nat_gateway_names = {
"us-east-1a" = "example-natgwa"
"us-east-1b" = "example-natgwb"
}
map(string){}no
nat_gateway_tagsn/amap(string){}no
subnetsMap of Subnets where to create the NAT Gateways. Each map's key is the availability zone name and each map's object has an attribute id identifying AWS Subnet. Importantly, the traffic returning from the NAT Gateway uses the Subnet's route table.
The keys of this input map are used for the output map endpoints.
Example for users of module subnet_set:subnets = module.subnet_set.subnetsExample:subnets = {
"us-east-1a" = { id = "snet-123007" }
"us-east-1b" = { id = "snet-123008" }
}
map(object({
id = string
tags = map(string)
}))
n/ayes

Outputs

NameDescription
eipsThe map of Elastic IP objects. Only valid if create_nat_gateway is at the default true value.
nat_gatewaysThe map of NAT Gateway objects.
next_hop_setThe Next Hop Set object, useful as the input to the vpc_route module. Example:next_hop_set = {
ids = {
"us-east-1a" = "nat-0ddf598f93a8ea8ae"
"us-east-1b" = "nat-0862c4b707b012111"
}
id = null
type = "nat_gateway"
}