# hashicorp/terraform-azurerm-terraform-enterprise-hvd architecture

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

- Interactive diagram: https://gitdiagram.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd
- Repository: https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd

## Overview

The project is a Terraform module designed specifically to deploy Terraform Enterprise (TFE) on Microsoft Azure. The module adheres to HashiCorp’s Validated Designs (HVD) and sets up a TFE deployment on Azure VMs using container runtimes (Docker for Ubuntu and Podman for RHEL). Besides deploying the TFE application itself, the module provisions all the required infrastructure components on Azure – such as load balancers, virtual machine scale sets (VMSS) for the TFE application nodes, a PostgreSQL Flexible Server for the database, a Redis cache, and an Azure Storage Account for object storage. In addition, there are resources for Azure DNS (both public and private), Key Vault integrations for pulling in sensitive information (certificates, passwords, and keys), as well as private endpoints for enhanced security.

##### Main Components
a. Infrastructure Core:
- Azure Resource Group: It hosts all resources.
- Azure Virtual Network (VNet): Illustrate subnets for VMs, load balancer, database, and other components.
b. Compute and Application Layer:
- Virtual Machine Scale Set (VMSS): Represents the TFE application nodes running either Docker or Podman containers. Include annotations for the use of either container runtime.
c. Networking and Access:
- DNS Components: Both public DNS records and private DNS zones (if enabled) should be represented, indicating how the FQDN (tfe_fqdn) is resolved by clients.
d. Data and Storage:
- Azure Redis Cache: Represented along with its secured connection settings (TLS enabled, authentication, and private endpoint).
e. Security and Configuration:
- Key Vault: Central to bootstrapping the deployment, it contains the TFE license, encryption password, database credentials, and TLS certificates.
- Role Assignments and Access Policies: Indicate that there are various access policies (for the VM, PostgreSQL, Storage Account, etc.) that bind identities with required permissions.

##### Relationships and Interactions
- Interactions with external logging systems (e.g., Azure Log Analytics Workspace) if the log forwarding feature is enabled.
- Control path from Terraform (which deploys and manages these resources) to the Azure resources. You might represent the Terraform CLI as a separate entity that “pushes” configuration to Azure.

##### Architectural Patterns and Design Principles
- The module follows the “Infrastructure as Code” paradigm with Terraform, and employs a modular design (indicated by the organized file layout). Emphasize important patterns such as separation of concerns (compute, network, storage, security).
- Use a layered approach: base infrastructure (VNet, resource group), compute (VMSS), and back-end services (database, storage, cache) are conceptually separated.
- Data security and secret management are enforced via integration with Azure Key Vault.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    Client["Clients"]:::external
    Terraform["Terraform CLI"]:::external

    %% Top Level: Azure GovCloud Environment Notice
    GovNote["Azure Government Cloud Deployment<br/>(govcloud=true)"]:::govcloud

    %% Infrastructure Core
    subgraph "Infrastructure Core"
        AR["Azure Resource Group"]:::infra
        VNet["Azure Virtual Network (VNet)"]:::infra
    end

    %% Networking and Access
    subgraph "Networking and Access"
        LB["Azure Load Balancer<br/>(Internal)"]:::network
        DNS["DNS Components<br/>(Public & Private Zones)"]:::network
    end

    %% Compute and Application Layer
    subgraph "Compute and Application Layer"
        VMSS["Azure VMSS (TFE Nodes)<br/>(Container Runtime: Docker/Podman)"]:::compute
        TFEContainer["TFE Application Container<br/>(Image Version set via Module Inputs)"]:::compute
    end

    %% Data and Storage
    subgraph "Data and Storage"
        PS["PostgreSQL Flexible Server<br/>(HA, backup retention:35d)"]:::database
        Redis["Azure Redis Cache<br/>(TLS enabled, secured)"]:::database
        Storage["Azure Storage Account<br/>(Blob Storage)"]:::database
    end

    %% Security and Configuration
    subgraph "Security and Configuration"
        KV["Azure Key Vault<br/>(TFE license, credentials, TLS certs)"]:::security
    end

    %% Relationships
    Client -->|"sends requests"| LB
    LB -->|"forwards traffic"| VMSS
    VMSS -->|"runs container"| TFEContainer
    TFEContainer -->|"queries/updates"| PS
    TFEContainer -->|"caches data"| Redis
    TFEContainer -->|"stores objects"| Storage
    KV -->|"provides secrets"| VMSS
    Terraform -->|"deploys/configures"| AR
    Terraform -->|"deploys/configures"| VNet
    Terraform -->|"deploys/configures"| LB
    Terraform -->|"deploys/configures"| DNS
    Terraform -->|"deploys/configures"| VMSS
    Terraform -->|"deploys/configures"| PS
    Terraform -->|"deploys/configures"| Redis
    Terraform -->|"deploys/configures"| Storage
    Terraform -->|"manages"| KV

    %% GovCloud Annotation Flow
    GovNote --- AR
    GovNote --- LB
    GovNote --- PS
    GovNote --- Redis
    GovNote --- Storage

    %% Styles for clarity and color
    classDef infra fill:#E0E0E0,stroke:#333,stroke-width:2px;
    classDef compute fill:#B3D4FC,stroke:#333,stroke-width:2px;
    classDef network fill:#C2F0C2,stroke:#333,stroke-width:2px;
    classDef database fill:#FFF2B2,stroke:#333,stroke-width:2px;
    classDef security fill:#F9C2C2,stroke:#333,stroke-width:2px;
    classDef external fill:#D9E4FF,stroke:#333,stroke-width:2px;
    classDef govcloud fill:#FAD7A0,stroke:#D35400,stroke-width:3px;

    %% Click Events for Component Mapping
    click AR "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/resource_group.tf"
    click VMSS "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/compute.tf"
    click TFEContainer "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/templates/tfe_custom_data.sh.tpl"
    click LB "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/load_balancer.tf"
    click DNS "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/dns.tf"
    click PS "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/postgresql.tf"
    click Redis "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/redis.tf"
    click Storage "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/blob_storage.tf"
    click GovNote "https://github.com/hashicorp/terraform-azurerm-terraform-enterprise-hvd/blob/main/docs/govcloud-deployment.md"
```
