Files
terraform-aws-vpc-factory/README.md
T
2024-05-01 14:50:47 +02:00

5.6 KiB

Terraform module - VPC Factory

Terraform VPC factory module creates a VPC with as many subnet tiers as described in subnet_groups attribute. For each subnet tier, a subnet is created in each selectec availability zones in availability_zones attribute. If these attributes are not specified, 2 tiers are creates : public and private in the 2 first availability zones of the current AWS region.An Internet Gateway is configured as default route for public tier's subnets and a NAT Gateway in each public subnets is created and configured as default route for private tier's subnets.

The default CIDR block for VPC is 10.0.0.0/16, but it can be customized with cidr_block.

By default, Network ACLs are configured to allow all ingress/egress.

Usage

# Defaults
module "network" {
  source = "git:https://github.com/thunderbal/terraform-aws-vpc-factory?ref=main"
}


# Custom example
module "network" {
  source = "git:https://github.com/thunderbal/terraform-aws-vpc-factory?ref=main"

  prefix_name          = "example"
  cidr_block           = "10.0.0.0/16"
  availability_zones   = ["eu-west-1a", "eu-west-1b"]
  network_acl_disabled = true

  subnet_groups = {
    dmz = {
      default_route = "igw"
      cidr_block    = "10.0.0.0/26"
    }
    frontend = {
      default_route = "ngw/pub"
      cidr_block = "10.0.16.0/20"
    }
    backend = {
      cidr_block = "10.0.32.0/20"
    }
  }
}

By default, Network ACLs allow alltrafic. Set network_acl_disabled to false to block all trafic by default.

prefix_name is used in tag Name to identify resources created by this module.

If availability_zones is not specified, module use 2 availability zones in the target region.

All subnet_groups must be given a cidr_block within cidr_bloc (default 10.0.0.0/16) provided to the module. Each block which wil be cut into several sub-blocks to have a subnet per availability zone for each groups. Group's cidr_block must not overlap each others .

Requirements

Name Version
terraform >=1.3.0
aws >=4.0

Providers

Name Version
aws 5.47.0

Modules

No modules.

Resources

Name Type
aws_default_network_acl.self resource
aws_default_route_table.self resource
aws_default_security_group.self resource
aws_default_vpc_dhcp_options.self resource
aws_eip.self resource
aws_internet_gateway.self resource
aws_nat_gateway.self resource
aws_network_acl_rule.all_egress resource
aws_network_acl_rule.all_ingress resource
aws_route_table.self resource
aws_route_table_association.public resource
aws_subnet.self resource
aws_vpc.self resource
aws_availability_zones.current data source

Inputs

Name Description Type Default Required
availability_zones Target availability zones. list(string) null no
cidr_block The IPv4 CIDR block for the VPC. string null no
network_acl_disabled If disabled, default Network ACLs allow all inbound and outbound protocols. bool true no
prefix_name Value used to prefix resources name. string null no
subnet_groups One subnet in each availablity zone is created per subnet group.
map(object({
cidr_block = string
default_route = optional(string, "")
}))
null no

Outputs

Name Description
aws_availability_zones List of available AZ names.
subnet_ids Map of public subnet IDs.
vpc value