This Terraform module creates a full-fledged highly available AWS VPC. The intention of this module is to deploy a straight-forward highly available IPv4 VPC without too much hassle.
- Public subnets in every availability zone
- Private subnets in every availability zone
- NAT gateway in every availability zone
- Internet gateway
- Custom configured route table for public subnets
- Custom configured route tables for every private subnet
module "aws_ha_vpc" {
source = "github.com/binxio/terraform-aws-ha-vpc-module"
cidr_block = "10.0.0.0/20"
subnet_newbits = 4
tags = {
Key = "Value"
}
}
We create a public and private availability zone in every availability zone of a particular region (the private subnets are created on top of the already calculated public subnet cidr ranges). To calculate the cidr block of a subnet, we use the following formula:
cidrsubnet(var.cidr_block, var.subnet_newbits, availability_zone_count)
Consider a region with 3 availability zones and a VPC with the range 10.0.0.0/20
.
The cidr block ranges of the public subnets are:
> cidrsubnet("10.0.0.0/20", 3, 0)
"10.0.0.0/23"
> cidrsubnet("10.0.0.0/20", 3, 1)
"10.0.2.0/23"
> cidrsubnet("10.0.0.0/20", 3, 2)
"10.0.4.0/23"
The cidr block ranges of the private subnets are:
> cidrsubnet("10.0.0.0/20", 3, 3)
"10.0.6.0/23"
> cidrsubnet("10.0.0.0/20", 3, 4)
"10.0.8.0/23"
> cidrsubnet("10.0.0.0/20", 3, 5)
"10.0.10.0/23"
No requirements.
Name | Version |
---|---|
aws | 4.2.0 |
No modules.
Name | Type |
---|---|
aws_eip.ngws | resource |
aws_internet_gateway.igw | resource |
aws_nat_gateway.ngw | resource |
aws_route.igw | resource |
aws_route.ngw | resource |
aws_route_table.private_crt | resource |
aws_route_table.public_crt | resource |
aws_route_table_association.private_subnets | resource |
aws_route_table_association.public_subnets | resource |
aws_subnet.private_subnet | resource |
aws_subnet.public_subnet | resource |
aws_vpc.main | resource |
aws_availability_zones.available | data source |
aws_region.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
cidr_block | Classless Inter-Domain Routing (CIDR) block | string |
n/a | yes |
enable_dns_support | Enable DNS support | bool |
true |
no |
enable_dns_hostnames | Enable DNS hostnames | bool |
false |
no |
subnet_newbits | Subnet mask bits | string |
n/a | yes |
tags | Tags that will be applied to all resources | map(any) |
{} |
no |
Name | Description |
---|---|
vpc_id | Outputs the unique VPC identifier |
public_subnet_ids | Outputs the public subnet identifiers |
private_subnet_ids | Outputs the private subnet identifiers |