Skip to content

Practical and easy to follow Terraform module for AWS VPC

License

Notifications You must be signed in to change notification settings

ishuar/terraform-aws-vpc

Repository files navigation

License Contributors Issues Forks Stargazers


AWS VPC Terraform Module

🌩️ Terraform Module For Simplifying AWS VPC Creation 🌩️
Report Bug or Request Feature

Background Knowledge or External Documentation

Pre-requisites

Name Version Used Help Required
Terraform >= 1.3.0 Install Terraform Yes
AWS Account N/A Create AWS account yes

⭐️ Don't forget to give the project a star! Thanks again! ⭐️

Introduction

🚀 This module is your ticket to effortlessly create a Virtual Private Cloud (VPC). Whether you're a seasoned cloud architect or just getting started, this module streamlines the process, giving you more time to focus on what truly matters. 🚀

Available Features

  • AWS VPC Creation.
  • AWS VPC Multiple Public and Private Subnets Creation.
  • Optional Bootstrap routing
  • Optional internet Gateway creation with a default route in public subnets.

Usage

## simple vpc

module "simple_vpc" {

  source  = "ishuar/vpc/aws"
  version = "~> 2.0"

  prefix     = "simple"
  env        = "dev"
  region     = "eu-central-1"
  cidr_block = "10.1.0.0/16"

  ## Subnets
  public_subnets = [
    {
      name              = "subnet01"
      cidr_block        = "10.1.1.0/24"
      availability_zone = "eu-central-1a"
    },
    # {
    #   name              = "subnet02"
    #   cidr_block        = "10.1.3.0/24"
    #   availability_zone = "eu-central-1b"
    # }
  ]

  private_subnets = [
    {
      name              = "subnet01"
      cidr_block        = "10.1.2.0/24"
      availability_zone = "eu-central-1a"
    },
    # {
    #   name              = "subnet02"
    #   cidr_block        = "10.1.4.0/24"
    #   availability_zone = "eu-central-1b"
    # }
  ]
}

Examples

Examples are availabe in examples directory.

Submodule

Requirements

Name Version
terraform >= 1.3
aws ~>5.14

Providers

Name Version
aws ~>5.14

Modules

No modules.

Resources

Name Type
aws_ec2_instance_connect_endpoint.this resource
aws_internet_gateway.this resource
aws_route.private resource
aws_route.public resource
aws_route.public_subnet_default_to_igw resource
aws_route_table.private resource
aws_route_table.public resource
aws_route_table_association.private resource
aws_route_table_association.public resource
aws_subnet.private_subnet resource
aws_subnet.public_subnet resource
aws_vpc.this resource

Inputs

Name Description Type Default Required
cidr_block (optional) describe your variable string n/a yes
assign_generated_ipv6_cidr_block (Optional) Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block. Default is false. Conflicts with ipv6_ipam_pool_id bool null no
create_private_route_table (optional) Whether to create the initial/bootstrap private route tables and routes or not? bool false no
enable_dns_hostnames (Optional) A boolean flag to enable/disable DNS hostnames in the VPC. Defaults false. bool null no
enable_dns_support (Optional) A boolean flag to enable/disable DNS support in the VPC. Defaults to true. bool null no
enable_instance_connect_endpoint (optional) Whether to enable instance connect endpoint or not? bool false no
env (Optional) Env name to use in resource naming. string "dev" no
instance_connect_endpoint_tags (Optional) Map of tags to assign to this ec2 instance connect endpoint resource map(string) {} no
instance_tenancy (Optional) A tenancy option for instances launched into the VPC. Default is default, which ensures that EC2 instances launched in this VPC use the EC2 instance tenancy attribute specified when the EC2 instance is launched. The only other option is dedicated, which ensures that EC2 instances launched in this VPC are run on dedicated tenancy instances regardless of the tenancy attribute specified at launch. This has a dedicated per region fee of $2 per hour, plus an hourly per instance usage fee. string null no
ipv4_ipam_pool_id (Optional) The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across AWS Regions and accounts. Using IPAM you can monitor IP address usage throughout your AWS Organization. string null no
ipv4_netmask_length (Optional) The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4_ipam_pool_id. string null no
ipv6_cidr_block (Optional) IPv6 CIDR block to request from an IPAM Pool. Can be set explicitly or derived from IPAM using ipv6_netmask_length. string null no
ipv6_cidr_block_network_border_group (Optional) By default when an IPv6 CIDR is assigned to a VPC a default ipv6_cidr_block_network_border_group will be set to the region of the VPC. This can be changed to restrict advertisement of public addresses to specific Network Border Groups such as LocalZones. string null no
ipv6_ipam_pool_id (Optional) IPAM Pool ID for a IPv6 pool. Conflicts with assign_generated_ipv6_cidr_block. string null no
ipv6_netmask_length (Optional) Netmask length to request from IPAM Pool. Conflicts with ipv6_cidr_block. This can be omitted if IPAM pool as a allocation_default_netmask_length set. Valid values: 56. string null no
prefix (Optional) Prefix to use in resource naming. string "" no
preserve_client_ip (Optional) Indicates whether your client's IP address is preserved as the source. string true no
private_subnet_routes (optional) Private route rules block.
"One of the destination_cidr_block or destination_prefix_list_id argument must be supplied:"
One of the following target arguments must be supplied:
- carrier_gateway_id - Identifier of a carrier gateway. This attribute can only be used when the VPC contains a subnet which is associated with a Wavelength Zone.
- egress_only_gateway_id - Identifier of a VPC Egress Only Internet Gateway.
- nat_gateway_id - Identifier of a VPC NAT gateway.
- network_interface_id - Identifier of an EC2 network interface.
- transit_gateway_id - Identifier of an EC2 Transit Gateway.
- vpc_endpoint_id - Identifier of a VPC Endpoint.
- vpc_peering_connection_id - Identifier of a VPC peering connection.
map(object({
destination_cidr_block = optional(string, null)
destination_prefix_list_id = optional(string, null)
transit_gateway_id = optional(string, null)
nat_gateway_id = optional(string, null)
vpc_endpoint_id = optional(string, null)
carrier_gateway_id = optional(string, null)
egress_only_gateway_id = optional(string, null)
network_interface_id = optional(string, null)
vpc_peering_connection_id = optional(string, null)
}))
{} no
private_subnets (optional) Private Subnets created within the VPC
list(object({
name = optional(string)
cidr_block = optional(string)
availability_zone_id = optional(string)
availability_zone = optional(string)
enable_dns64 = optional(bool, null)
enable_resource_name_dns_aaaa_record_on_launch = optional(bool, null)
enable_resource_name_dns_a_record_on_launch = optional(bool, null)
ipv6_cidr_block = optional(string, null)
private_dns_hostname_type_on_launch = optional(string, null)
private_subnet_tags = optional(map(string), {})
}))
[] no
public_subnet_routes (optional) Public route rules block.
"One of the destination_cidr_block or destination_prefix_list_id argument must be supplied:"
One of the following target arguments must be supplied:
- carrier_gateway_id - Identifier of a carrier gateway. This attribute can only be used when the VPC contains a subnet which is associated with a Wavelength Zone.
- network_interface_id - Identifier of an EC2 network interface.
- transit_gateway_id - Identifier of an EC2 Transit Gateway.
- vpc_endpoint_id - Identifier of a VPC Endpoint.
- vpc_peering_connection_id - Identifier of a VPC peering connection.
map(object({
destination_cidr_block = optional(string, null)
destination_prefix_list_id = optional(string, null)
transit_gateway_id = optional(string, null)
vpc_endpoint_id = optional(string, null)
carrier_gateway_id = optional(string, null)
network_interface_id = optional(string, null)
vpc_peering_connection_id = optional(string, null)
}))
{} no
public_subnets (optional) Public Subnets created within the VPC
list(object({
name = optional(string)
cidr_block = optional(string)
availability_zone_id = optional(string)
availability_zone = optional(string)
map_public_ip_on_launch = optional(bool, true)
assign_ipv6_address_on_creation = optional(bool, null)
enable_dns64 = optional(bool, null)
enable_resource_name_dns_aaaa_record_on_launch = optional(bool, null)
enable_resource_name_dns_a_record_on_launch = optional(bool, null)
ipv6_cidr_block = optional(string, null)
private_dns_hostname_type_on_launch = optional(string, null)
public_subnet_tags = optional(map(string), {})
}))
[] no
region (Optional) Region to use in resource naming. string "eu-central-1" no
security_group_ids (Optional) One or more security groups to associate with the endpoint. If you don't specify a security group, the default security group for the VPC will be associated with the endpoint. list(string) null no
tags (Optional) A map of tags to assign to the resource. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level. map(string) {} no
use_created_igw_for_public_routing (optional) Whether to use IGW created within the module for public route to internet or not? bool true no

Outputs

Name Description
igw_id Internet gateway Id.
private_route_table_id Private route table Id.
private_subnet_cidr_blocks Key value object for private subnet CIDR blocks.
private_subnet_ids Key value object for private subnet IDs.
public_route_table_id Public route table Id.
public_subnet_cidr_blocks Key value object for public subnet CIDR blocks.
public_subnet_ids Key value object for public subnet IDs.
vpc_cidr_block The VPC CIDR block.
vpc_id The ID of the VPC.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have any suggestion that would make this project better, feel free to fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement" with your suggestion.

⭐️ Don't forget to give the project a star! Thanks again! ⭐️

See CONTRIBUTING for more information.

License

Released under MIT by @ishuar.

Contact

Back To Top ⬆️