# azure-terraform/terraform-azurerm-virtual-network architecture

> Architecture diagram of the GitHub repository azure-terraform/terraform-azurerm-virtual-network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure-terraform/terraform-azurerm-virtual-network
- Repository: https://github.com/azure-terraform/terraform-azurerm-virtual-network

## Overview

##### Project type and purpose
- This is a Terraform module (“Azure – Virtual Network Module”) designed to provision Azure infrastructure: a Virtual Network (VNet), its subnets, route tables, network security groups (NSGs), and peerings.
- It is not an application codebase, but an Infrastructure-as-Code (IaC) project that defines reusable infrastructure components.

##### File structure
- Top-level files:
- main.tf, variables.tf, output.tf, locals.tf – the root module that instantiates resources (azurerm_virtual_network, azurerm_route_table, azurerm_subnet, peerings, etc.)
- versions.tf – provider and Terraform version constraints
- examples/ – three example scenarios (aks, bastion, custom_routes) each with its own main.tf to demonstrate module usage
- .github/workflows – CI for doc generation, linting, or validation
- subnet/ – a child module (re-used for both AKS subnets and generic subnets) with its own main.tf, locals.tf, output.tf, variables.tf
- Key patterns:
- Modular structure (root vs subnet child module)
- Examples to illustrate different subnet configurations
- Use of maps/objects to drive variable-driven provisioning

##### README for additional insights
- It lists inputs (address_space, subnets, route_tables, peers, naming rules, tags) and outputs (vnet, subnets, NSG IDs/names, route_tables).
- It references the AzureRM provider, Terraform ≥0.13.0, and links to Azure resource docs.
- It documents the two modules (root and ./subnet) and the resources created (virtual_network, subnet, route_table, route, peering, subnet_route_table_association).

##### Elements
- Clear labels for: Terraform CLI, Root Module, Subnet Module, AzureRM Provider, Azure ARM components
- From CLI → Root Module
- Root Module → Subnet Module
- Modules → AzureRM provider
- Provider → Azure ARM
- Another for provider plugin
- A third for actual Azure resources
- Modules in containers to visually distinguish root vs child modules
- Number of instances (e.g., “n subnets created via subnet module”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User and CLI
    User["User"]:::external
    TerraformCLI["Terraform CLI"]:::terraform

    %% Project Files
    subgraph "Project Files"
        direction TB
        versions["versions.tf"]:::tf_file
        README["README.md"]:::tf_file
        DocCI[".github/workflows/documentation.yml"]:::tf_file
        LICENSE["LICENSE.md"]:::tf_file
        GITIGNORE[".gitignore"]:::tf_file
        BastionGit["examples/bastion/.gitignore"]:::tf_file
    end

    %% Root Module
    subgraph "Root Module"
        direction TB
        MainTF["main.tf"]:::tf_file
        VariablesTF["variables.tf"]:::tf_file
        LocalsTF["locals.tf"]:::tf_file
        OutputTF["output.tf"]:::tf_file
    end

    %% Subnet Child Module
    subgraph "Subnet Module"
        direction TB
        SubMain["main.tf"]:::tf_file
        SubVars["variables.tf"]:::tf_file
        SubLocals["locals.tf"]:::tf_file
        SubOutput["output.tf"]:::tf_file
    end

    %% Examples
    subgraph "Examples"
        direction TB
        AKS["aks/main.tf"]:::example
        Bastion["bastion/main.tf"]:::example
        Custom["custom_routes/main.tf"]:::example
    end

    %% Provider
    Provider["AzureRM Provider"]:::provider

    %% Azure Resources
    subgraph "Azure Subscription / Resource Group"
        direction TB
        VNet["Virtual Network"]:::azureres
        subgraph "Subnets"
            direction TB
            AKSSub["AKS Subnets (n)"]:::azureres
            CustSub["Custom Subnets (n)"]:::azureres
        end
        NSGs["Network Security Groups (NSGs)"]:::azureres
        RT["Route Tables"]:::azureres
        Peer["Virtual Network Peerings"]:::azureres
    end

    %% Connections
    User --> TerraformCLI
    TerraformCLI --> MainTF
    TerraformCLI --> VariablesTF
    TerraformCLI --> LocalsTF
    TerraformCLI --> OutputTF
    TerraformCLI --> versions
    TerraformCLI --> README
    TerraformCLI --> DocCI
    TerraformCLI --> LICENSE
    TerraformCLI --> GITIGNORE

    MainTF --> SubMain
    VariablesTF --> SubMain
    LocalsTF --> SubMain
    OutputTF --> SubMain

    AKS --> MainTF
    Bastion --> MainTF
    Custom --> MainTF

    SubMain --> Provider
    SubVars --> Provider
    SubLocals --> Provider
    SubOutput --> Provider

    Provider --> VNet
    Provider --> AKSSub
    Provider --> CustSub
    Provider --> NSGs
    Provider --> RT
    Provider --> Peer

    %% Click Events
    click MainTF "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/main.tf"
    click VariablesTF "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/variables.tf"
    click LocalsTF "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/locals.tf"
    click OutputTF "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/output.tf"
    click SubMain "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/subnet/main.tf"
    click SubVars "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/subnet/variables.tf"
    click SubLocals "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/subnet/locals.tf"
    click SubOutput "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/subnet/output.tf"
    click AKS "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/examples/aks/main.tf"
    click Bastion "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/examples/bastion/main.tf"
    click Custom "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/examples/custom_routes/main.tf"
    click versions "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/versions.tf"
    click README "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/README.md"
    click DocCI "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/.github/workflows/documentation.yml"
    click LICENSE "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/LICENSE.md"
    click GITIGNORE "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/.gitignore"
    click BastionGit "https://github.com/azure-terraform/terraform-azurerm-virtual-network/blob/master/examples/bastion/.gitignore"

    %% Styles
    classDef terraform fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef tf_file fill:#ffffff,stroke:#333,stroke-width:1px;
    classDef provider fill:#dae8fc,stroke:#333,stroke-width:1px;
    classDef azureres fill:#e1d5e7,stroke:#333,stroke-width:1px;
    classDef example fill:#d5e8d4,stroke:#333,stroke-width:1px;
    classDef external fill:#fff2cc,stroke:#333,stroke-width:1px;
```
