# terraform-aws-modules/terraform-aws-vpc architecture

> Architecture diagram of the GitHub repository terraform-aws-modules/terraform-aws-vpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/terraform-aws-modules/terraform-aws-vpc
- Repository: https://github.com/terraform-aws-modules/terraform-aws-vpc

## Overview

##### Component Identification
- VPC Core: Represent the overall VPC which wraps all networking resources.
- Subnets: Break the VPC into multiple subnet types – public, private, intra, database, redshift, elasticache, etc. Each subnet may have associated CIDR block details and attributes (IPv4, IPv6).
- Routing: Include Route Tables for each subnet type (default/public, private, intra, etc.) as well as associations linking subnets with corresponding route tables.
- Network ACLs & Security Groups: Identify dedicated or shared Network ACLs for different subnet groups.
- VPC Flow Logging: Add components for CloudWatch log groups, IAM roles/policies related to logging.
- External and Optional Resources: Show integration points with external Elastic IPs (especially when reusing NAT IPs) and examples of IPAM use for CIDR allocation.

##### Relationships and Interactions
- Public subnets connect to the Internet Gateway.
- Private subnets route traffic either through NAT Gateways or via a single shared NAT Gateway.
- Specialized subnets (intra, database, redshift, elasticache) are connected to their specific route tables and have separate network ACLs.
- Conditional relationships: for instance, when VPC Flow Logs are enabled, show the connection from VPC resources to the CloudWatch log group via the IAM role.
- If VPN gateway is enabled, indicate its attachment to the VPC and the associated route propagation to private and intra route tables.

##### Pattern and Design Principles
- Modular design: Emphasize the module’s reusability with “input” configuration across multiple examples.
- Separation of concerns: Distinguish components based on public vs. private network segregation (e.g., subnets, route tables, NAT versus IGW); network ACLs isolate different subnet types.

##### Technologies and Frameworks
- Terraform as the IaC tool.
- AWS Cloud resources: VPC, Subnet, Internet Gateway, NAT Gateway, VPN Gateway, CloudWatch, and AWS IAM.
- Support for both IPv4 and IPv6 addressing.

- Grouping related resources (all network ACLs in a cluster, all route table associations together) for clarity.

This thorough approach will give stakeholders, including principal software engineers, a clear high-level and detailed view of how the VPC is constructed, managed, and integrated within the AWS environment using this Terraform module.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "External Resources"
    IGW["Internet Gateway"]:::gateway
    VPN["VPN Gateway"]:::gateway
  end

  VPC["VPC Core (10.0.0.0/16)"]:::vpc
  IGW -->|"attached"| VPC
  VPN -->|"route propagation"| VPC

  subgraph "VPC Resources"
    PS["Public Subnets (for egress traffic)"]:::subnet
    NAT["NAT Gateway"]:::gateway
    PrS["Private Subnets (with NAT)"]:::subnet
    SS["Specialized Subnets (Intra, Database, Redshift, ElastiCache)"]:::subnet
    RT["Route Tables & Associations"]:::routing
    ACL["Network ACLs & Security Groups"]:::security
  end

  VPC -->|"configures"| PS
  VPC -->|"configures"| PrS
  VPC -->|"configures"| SS
  
  PS -->|"routes traffic"| IGW
  PS -->|"hosts"| NAT
  PrS -->|"routes through"| NAT
  
  PS --> RT
  PrS --> RT
  SS --> RT
  
  PS --> ACL
  PrS --> ACL
  SS --> ACL

  VPC -->|"logs traffic"| FL["VPC Flow Logging (CloudWatch & IAM)"]:::logging
  VPC -->|"configures"| IPAM["IPAM Integration (CIDR Allocation)"]:::integration
  VPC -->|"enables"| EP["VPC Endpoints (Optional)"]:::integration
  VPC -->|"integrates"| OUT["Outposts Integration"]:::integration

  VPN -->|"connects to"| PrS

  click VPC "https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/main.tf"
  click PS "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete"
  click PrS "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete"
  click SS "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete"
  click IGW "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/simple"
  click NAT "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/simple"
  click RT "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/separate-route-tables"
  click ACL "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/network-acls"
  click FL "https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/vpc-flow-logs.tf"
  click IPAM "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/ipam"
  click OUT "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/outpost"
  click EP "https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/modules/vpc-endpoints"

  classDef vpc fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
  classDef subnet fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
  classDef gateway fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
  classDef routing fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
  classDef security fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
  classDef logging fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
  classDef integration fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
```
