This Terraform module creates a fully configured Virtual Private Cloud (VPC) in AWS, complete with public and private subnets, internet gateway, NAT gateway, eip, route tables, network ACLs, and security groups.
module "custom_vpc" {
source = "../../"
vpc_cidr = "10.0.0.0/16"
region = "eu-west-1"
vpc_name = "my-vpc"
igw = "my-igw"
public_subnet_cidr = ["10.0.1.0/24"]
private_subnet_cidr = ["10.0.2.0/24"]
availability_zones = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
container_subnet_cidr = "10.0.7.0/24"
nat_gateway = "my-nat-gateway"
nat_eip = "my-nat-eip"
nacl = "my-nacl"
security_group = "my-security-group"
environment = "dev"
environment_type = "test"
enable_public_subnets = true
enable_private_subnets = true
enable_container_subnet = true
enable_nat_gateway = true
enable_ingress = true
enable_egress = true
vpc_tags = {
"Department" = "Engineering"
"Owner" = "xx"
}
tags = {
"Project" = "xx"
"Team" = "xx"
}
}
Creates an AWS VPC with the specified CIDR block and tags.
Creates an Internet Gateway and attaches it to the VPC.
Fetches the list of available availability zones in the specified region.
Creates subnets (public, private, container) within the VPC, using the specified CIDR blocks and availability zones.
Creates a route table for public subnets, with a default route to the Internet Gateway.
Associates the public subnets with the public route table.
Creates a NAT Gateway in the first public subnet, if enabled.
Creates an Elastic IP for the NAT Gateway, if enabled.
Creates a Network ACL with custom inbound and outbound rules.
Creates inbound and outbound rules for the Network ACL.
Associates the Network ACL with the public subnets.
Creates a security group with custom ingress and egress rules.
This project is licensed under the MIT License - see the LICENSE file for details.
Name | Version |
---|---|
terraform | >= 0.13.0 |
aws | >= 3.73 |
Name | Version |
---|---|
aws | >= 3.73 |
No modules.
Name | Type |
---|---|
aws_eip.nat_eip | resource |
aws_internet_gateway.internet_gateway | resource |
aws_nat_gateway.nat_gateway | resource |
aws_network_acl.nacl | resource |
aws_network_acl_association.public_subnet_nacl_association | resource |
aws_network_acl_rule.inbound_rules | resource |
aws_network_acl_rule.outbound_rules | resource |
aws_route_table.public_route_table | resource |
aws_route_table_association.public_subnet_route_table_associations | resource |
aws_security_group.my_security_group | resource |
aws_subnet.container_subnet | resource |
aws_subnet.private_subnets | resource |
aws_subnet.public_subnets | resource |
aws_vpc.vpc | resource |
aws_availability_zones.available_zones | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
availability_zones | List of availability zones | list(string) |
[ |
no |
container_subnet_cidr | CIDR block for the container subnet | string |
"10.0.7.0/24" |
no |
enable_container_subnet | Flag to enable container subnet | bool |
true |
no |
enable_egress | Enable or disable egress rules | bool |
true |
no |
enable_ingress | Enable or disable ingress rules | bool |
true |
no |
enable_nat_gateway | Flag to enable/disable NAT Gateway | bool |
false |
no |
enable_private_subnets | Flag to enable private app subnets | bool |
true |
no |
enable_public_subnets | Flag to enable public subnets | bool |
true |
no |
environment | The environment (e.g., dev, stg, prod) | string |
n/a | yes |
environment_type | The environment type (optional) | string |
null |
no |
igw | The name of the Internet Gateway | map |
{} |
no |
nacl | The name of the Network ACL | map |
{} |
no |
nat_eip | The name of the NAT Elastic IP | bool |
false |
no |
nat_gateway | Name for the NAT Gateway | string |
"nat-gateway" |
no |
private_subnet_cidr | CIDR block for the first private app subnet | list(string) |
[ |
no |
public_subnet_cidr | CIDR block for the second public subnet | list(string) |
[ |
no |
region | The AWS region where the VPC and its subnets will be created. | string |
n/a | yes |
security_group | The name of the Security Group | map |
{} |
no |
tags | General tags to be applied to resources | map(string) |
{} |
no |
vpc_cidr | The CIDR block for the VPC | string |
"10.0.0.0/16" |
no |
vpc_name | The name of the VPC | string |
"" |
no |
vpc_tags | Additional tags to be applied to the VPC and subnets | map(string) |
{} |
no |
Name | Description |
---|---|
availability_zones | The availability zones. |
container_subnet_id | The ID of the container subnet |
nacl_id | The ID of the Network ACL |
nat_eip_id | The ID of the NAT Elastic IP |
nat_gateway_id | The ID of the NAT Gateway |
private_subnet_ids | The IDs of the private app subnets |
public_subnet_ids | The IDs of the public subnets |
security_group_id | The ID of the Security Group |
vpc_id | The ID of the VPC |