/terraform-aws-nat

Terraform module which create a single NAT instance in the public subnet of a VPC that will route all private subnets egress to the NAT and then to the internet

Primary LanguageHCL

AWS nat instance module

Terraform module which create a single NAT instance in the public subnet of a VPC that will route all private subnets egress to the NAT and then to the internet.

Using a NAT instance instead of NAT gateway is a good way to save money on development environment.

Usage

# We use VPC module for the example
module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = "vpc"
  cidr = "10.0.0.0/16"

  azs             = ["eu-west-2a", "eu-west-2b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]

  enable_dns_support   = true
  enable_dns_hostnames = true

  enable_nat_gateway = false
  single_nat_gateway = false
  enable_vpn_gateway = false
}

module "nat" {
  source = "../.."

  name                    = "nat"
  instance_type           = "t4g.nano"
  vpc_id                  = module.vpc.vpc_id
  public_subnet_id        = module.vpc.public_subnets[0]
  private_route_table_ids = module.vpc.private_route_table_ids
}

Requirements

No requirements.

Providers

Name Version
aws n/a

Modules

No modules.

Resources

Name Type
aws_instance.nat resource
aws_network_interface.this resource
aws_route.this resource
aws_security_group.this resource
aws_security_group_rule.egress resource
aws_security_group_rule.ingress resource
aws_ami.this data source
aws_vpc.this data source

Inputs

Name Description Type Default Required
enabled Enable module bool true no
instance_type Instance type string "t3.nano" no
name Nat instance name string n/a yes
private_route_table_ids IDs for private route table list(string) n/a yes
public_subnet_id Public subnet ID where nat instance is deployed string n/a yes
tags Optional tags for all resources map(string) {} no
vpc_id VPC Id string n/a yes

Outputs

Name Description
nat_instance_public_ip Nat instance public IP