Skip to main content

AWS Network Module

Overview

The AWS Network Module provides a reusable and scalable way to provision and manage complete networking infrastructure using Terraform.
It enables you to configure VPCs, subnets, route tables, internet gateways, NAT gateways, VPNs, VPC endpoints, and security groups in a modular and maintainable way.

This module supports both resource creation and data sources for all networking components, ensuring secure and highly available network architecture.


Features

  • 🚀 Reusable & Modular – Predefined structure for all networking resources.
  • 🌐 Flexible Networking – Configure public, private, and isolated subnets across multiple Availability Zones.
  • 🔒 Secure by Default – Integrates security groups, NACLs, and VPC endpoints for granular access control.
  • 🔄 Highly Available – Supports multi-AZ design, NAT gateways, and VPN connectivity.
  • 📜 Tagging & Documentation – Consistent tags and naming conventions across all network resources.
  • 🧩 Extensible – Can be integrated with other modules like EKS, Auto Scaling, ELB, and RDS.

Core Concepts

  1. Resources Module

    • Creates and manages the following networking components:
      • VPCs
      • Public, private, and isolated subnets
      • Route tables and routes
      • Internet Gateways
      • NAT Gateways
      • VPC Endpoints (Interface & Gateway)
      • VPN Gateways and Customer Gateways
      • Transit Gateways (optional)
      • Security Groups
      • Network ACLs
  2. Data Module

    • Fetches information about existing network resources.
    • Useful for referencing attributes like VPC ID, subnet IDs, security groups, and route table IDs.
  3. Separation of Concerns

    • resources/ handles creation of networking components.
    • data/ is focused on reading and referencing existing network resources.
    • Ensures clarity, reusability, and modular design.

Sample Usage

# DEPLOY COMPLETE AWS NETWORK MODULE

module "network" {
source = "github.com/anantacloud/terraform-aws-network-module/modules/resources"

# ==========================
# REQUIRED VARIABLES
# ==========================
vpc_name = "my-vpc"
cidr_block = "10.0.0.0/16"
public_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
private_subnets = ["10.0.3.0/24", "10.0.4.0/24"]
isolated_subnets = ["10.0.5.0/24", "10.0.6.0/24"]

# ==========================
# OPTIONAL VARIABLES
# ==========================
enable_nat_gateway = true
enable_vpn = false
enable_transit_gateway = false
enable_vpc_endpoints = true

tags = {
Environment = "dev"
Project = "my-app"
}
}

Required

NameDescriptionTypeExample
vpc_nameName of the VPCstring"my-vpc"
cidr_blockCIDR block for the VPCstring"10.0.0.0/16"
public_subnetsList of public subnet CIDRslist["10.0.1.0/24"]
private_subnetsList of private subnet CIDRslist["10.0.3.0/24"]
isolated_subnetsList of isolated subnet CIDRslist["10.0.5.0/24"]

Optional

NameDescriptionTypeDefault
enable_nat_gatewayCreate NAT gateways for private subnetsboolfalse
enable_vpnCreate VPN connectionsboolfalse
enable_transit_gatewayCreate Transit Gatewayboolfalse
enable_vpc_endpointsCreate VPC endpoints for services like S3, DynamoDBboolfalse
tagsKey-value tags to apply to all network resourcesmap{}