Skip to content

htec-infra/terraform-aws-nat-instance

AWS NAT Instance

Overview

Features

  • Autoscaling group that spreads nat instances across the AWS region
  • Spot instance support
  • Optional Elastic IP

Usage

module "nat_instance" {
  source              = "github.com/htec-infra/terraform-aws-nat-instance"
  environment         = "Development"
  name                = "Test"
  namespace           = "PoC"
  vpc_id              = "vpc-123456"
  public_subnets      = ["subnet-123456789"]
  allocate_elastic_ip = true
}

Requirements

Name Version
terraform >= 0.13
aws ~> 3.0

Providers

Name Version
aws ~> 3.0
template n/a

Modules

Name Source Version
net_interface ./modules/net-interface

Resources

Name Type
aws_autoscaling_group.this resource
aws_iam_instance_profile.this resource
aws_iam_role.this resource
aws_iam_role_policy.eni resource
aws_iam_role_policy_attachment.ssm resource
aws_launch_template.this resource
aws_security_group.this resource
aws_ami.this data source
aws_iam_policy_document.ec2_assume_role data source
aws_iam_policy_document.eni data source
aws_route_tables.private data source
aws_vpc.this data source
template_cloudinit_config.user_data data source

Inputs

Name Description Type Default Required
add_db_subnet_route Whether the DB subnet should have a route to the NAT Instance ENI bool false no
allocate_elastic_ip n/a bool false no
enabled Enable or not costly resources bool true no
environment Environment string n/a yes
health_check_grace_period How long ASG should wait before a health-check starts number 180 no
image_id AMI of the NAT instance. Default to the latest Amazon Linux 2 string "" no
instance_types Candidates of spot instance type for the NAT instance. This is used in the mixed instances policy list(string)
[
"t3a.nano",
"t3.nano"
]
no
key_name Name of the key pair for the NAT instance. You can set this to assign the key pair to the NAT instance string "" no
name Name for all the resources as identifier string n/a yes
namespace Module namespace string n/a yes
public_subnets IDs of the public subnets to place the NAT instance list(string) n/a yes
tags Tags applied to resources created with this module map(string) {} no
use_spot_instance Whether to use spot or on-demand EC2 instance bool true no
vpc_id ID of the VPC string n/a yes

Outputs

Name Description
iam_role_name Name of the IAM role for the NAT instance
sg_id ID of the security group of the NAT instance

Development

Prerequisites

Configurations

  • Configure pre-commit hooks
pre-commit install

Tests

  • Tests are available in test directory
  • In the test directory, run the below command
go test