# aws-samples/hub-and-spoke-with-inspection-vpc-terraform architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform
- Repository: https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform

## Overview

##### Project type and purpose
- This is an Infrastructure‐as‐Code project written in Terraform that deploys a sample AWS Hub-and-Spoke network architecture with an Inspection VPC using AWS Network Firewall.
- It provides two variants:
- A single-account deployment (in single-account/)
- A multi-account deployment (in multi-account/)

##### File structure
Top-level
- single-account/ – Terraform code for one AWS account, with:
– modules/compute (EC2, subnets, security groups)
– modules/iam_kms (IAM roles, KMS keys)
– main.tf, policy.tf, outputs.tf, providers.tf, variables.tf
- multi-account/ – Terraform code split by AWS account role:
– modules/compute – shared compute module
– networking-account/ – Hub VPC & Transit Gateway
– security-account/ – AWS Network Firewall & Security tooling
– spoke-account/ – Spoke VPC attachments
– each account folder has its own main.tf, providers.tf, variables.tf, outputs.tf

##### Inspect README for architectural clues
- Describes Hub-and-Spoke pattern, Inspection VPC, AWS Network Firewall

a. Main components to represent
- AWS Accounts (in multi-account variant):
– Networking (Hub VPC + Transit Gateway)
– Security (Inspection VPC + Network Firewall)
– Spoke (one or more Spoke VPCs)
- VPCs (Hub, Inspection, each Spoke)
- Transit Gateway (TGW) attachments (Hub, Spokes)
- AWS Network Firewall in the Inspection VPC
- Compute layer (EC2 instances or Autoscaling groups, via compute module)
- IAM & KMS services for encryption and permissions (via iam_kms module)
- Route tables & traffic flows between components

b. Relationships & interactions
1. Spoke VPCs route all outbound traffic to the Hub TGW.
2. Hub TGW forwards traffic to the Inspection VPC’s Firewall endpoints.
3. The Network Firewall processes/inspects traffic, then either returns it through the TGW or sends it to the Internet Gateway in the Hub VPC.
4. Compute instances in each VPC communicate across the TGW if permitted.
5. IAM & KMS enforce encryption at rest and secure API calls.

c. Architectural patterns & design principles
- Hub-and-Spoke network topology for centralized connectivity
- Multi-account separation of concerns (networking, security, workloads)
- Modular Terraform code (reusable compute and IAM/KMS modules)
- Policy-as-code for least-privilege via policy.tf and module variables

d. Key technologies & frameworks
- Terraform (modules, providers, variables, outputs)
- AWS VPC, Transit Gateway, Network Firewall, EC2, IAM, KMS
- AWS Organizations (implicit in multi-account setup)

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Single-Account Deployment"
    direction TB
    SAAccount["AWS Account"]:::account
    subgraph "VPCs & Resources"
      direction TB
      SAHubVPC["Hub VPC"]:::network
      SAInspectionVPC["Inspection VPC"]:::network
      SASpokeVPC["Spoke VPC"]:::network
      SAFirewall["AWS Network Firewall"]:::security
      SAEC2["EC2 Instances"]:::compute
      SAIAMKMS["IAM & KMS"]:::security
    end
    SAEC2 -->|communicates| SAHubVPC
    SASpokeVPC -->|"0.0.0.0/0 → TGW"| SAHubVPC
    SAHubVPC -->|"to Inspection"| SAFirewall
    SAFirewall -->|"inspected return"| SAHubVPC
    SAIAMKMS -->|secures API & data| SAEC2

    subgraph "Terraform Modules & Config"
      direction TB
      SAComputeModule["Compute Module"]:::module
      SAIAMKMSModule["IAM & KMS Module"]:::module
      SARootConfig["Root Config & Policies"]:::module
    end
    SAComputeModule -.->|uses| SAEC2
    SAIAMKMSModule -.->|uses| SAIAMKMS
    SARootConfig -.->|defines| SAHubVPC

    click SAComputeModule "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/tree/main/single-account/modules/compute"
    click SAIAMKMSModule "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/tree/main/single-account/modules/iam_kms"
    click SARootConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/single-account/main.tf"
    click SARootConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/single-account/providers.tf"
    click SARootConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/single-account/variables.tf"
    click SARootConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/single-account/outputs.tf"
    click SARootConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/single-account/policy.tf"
  end

  subgraph "Multi-Account Deployment"
    direction TB
    subgraph "Networking Account"
      direction TB
      NetworkingVPC["Hub VPC"]:::network
      TGW["Transit Gateway"]:::network
      IGW["Internet Gateway"]:::network
    end

    subgraph "Security Account"
      direction TB
      InspectionVPC["Inspection VPC"]:::network
      Firewall["AWS Network Firewall"]:::security
    end

    subgraph "Spoke Account"
      direction TB
      SpokeVPC["Spoke VPC"]:::network
      EC2["EC2 Instances"]:::compute
    end

    SpokeVPC -->|"0.0.0.0/0 → TGW"| TGW
    TGW -->|"attach"| NetworkingVPC
    TGW -->|"route to inspection"| Firewall
    Firewall -->|"inspected return"| TGW
    TGW -->|"route to internet"| IGW
    EC2 -->|cross-VPC comms| NetworkingVPC

    subgraph "Multi-Account Terraform Modules"
      direction TB
      MACCompute["Shared Compute Module"]:::module
      NetAccountConfig["Networking Account Config"]:::module
      SecAccountConfig["Security Account Config"]:::module
      SpkAccountConfig["Spoke Account Config"]:::module
    end
    MACCompute -.->|used by| EC2
    NetAccountConfig -.->|defines| NetworkingVPC
    SecAccountConfig -.->|defines| InspectionVPC
    SpkAccountConfig -.->|defines| SpokeVPC

    click MACCompute "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/tree/main/multi-account/modules/compute"
    click NetAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/networking-account/main.tf"
    click NetAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/networking-account/providers.tf"
    click NetAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/networking-account/variables.tf"
    click NetAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/networking-account/outputs.tf"
    click SecAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/security-account/main.tf"
    click SecAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/security-account/providers.tf"
    click SecAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/security-account/variables.tf"
    click SecAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/security-account/outputs.tf"
    click SpkAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/spoke-account/main.tf"
    click SpkAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/spoke-account/providers.tf"
    click SpkAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/spoke-account/variables.tf"
    click SpkAccountConfig "https://github.com/aws-samples/hub-and-spoke-with-inspection-vpc-terraform/blob/main/multi-account/spoke-account/outputs.tf"
  end

  classDef network fill:#cce5ff,stroke:#00529b,color:#00529b;
  classDef security fill:#ffd6cc,stroke:#9b1e00,color:#9b1e00;
  classDef compute fill:#d4edda,stroke:#155724,color:#155724;
  classDef module fill:#f0f0f0,stroke:#666666,color:#333333;
  classDef account fill:#f7f7f7,stroke:#333333,color:#333333,stroke-width:2px;
```
