# marcinkasprowicz/ultimate-terraform-folder-structure architecture

> Architecture diagram of the GitHub repository marcinkasprowicz/ultimate-terraform-folder-structure, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/marcinkasprowicz/ultimate-terraform-folder-structure
- Repository: https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure

## Overview

##### Main Components
- Environments: There are multiple environment directories under infrastructure/environments, including “com”, “pre”, “pro”, and “rev”. Each of these holds its own Terraform configuration (main.tf, outputs.tf, variables.tf, etc.), indicating the use of Terraform workspaces for environment segregation.
- Modules: There are two levels of modules. At the top-level “infrastructure/modules”, you have modules like “app”, “db”, and “queue” which encapsulate common infrastructure components. Additionally, within some environment folders (e.g., “com”) you see sub-modules such as “notifier” that are specific to that environment.
- Supporting Tools & Scripts: The repository includes package.json, a small “src” folder with an index.js file, and scripts (like install_terraform.sh). These likely support development, testing, or automation of the deployment process rather than directly being part of the infrastructure code.
- CI/CD & Versioning: Files like .travis.yml and .terraform-version help manage CI/CD and versioning of Terraform, indicating integration with build pipelines and environment management.

b. Module Layer: Illustrate the common modules (app, db, queue) as separate reusable components. Also, include any sub-modules (like the “notifier” module under the “com” environment) and show how these integrate with the environment configurations.
c. Tooling and Scripts: Add a supporting component for the automation and CI/CD tools (Travis CI, tfenv management, and the scripts folder). This component shows how external processes interact with the core Terraform configurations.

##### Architectural Patterns and Design Principles
- Modular Architecture: Emphasize that the repository follows a modular pattern, significantly reducing duplication by using shared Terraform modules for repeated infrastructure components.
- Environment Isolation: Highlight the segregation of environment-specific configurations through separate folders and the use of Terraform workspaces – an important design principle for separate lifecycle management.
- Infrastructure as Code (IaC): The entire structure is designed to be managed as code, allowing version control (with .gitignore) and continuous integration (via .travis.yml) for robust infrastructure provisioning.
- Reusability and Extensibility: The existence of both environment-specific and globally shared modules suggests a design that prioritizes reusability and ease of extending infrastructure components.

##### Summary
- Surround these core components with a layer representing CI/CD integration (Travis CI, tfenv) and automation scripts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Terraform Environments"
        E_com["com environment (config.tf, main.tf, outputs.tf, variables.tf)"]
        E_pre["pre environment (config.tf, main.tf, outputs.tf, variables.tf)"]
        E_pro["pro environment (config.tf, main.tf, outputs.tf, variables.tf)"]
        E_rev["rev environment (config.tf, main.tf, outputs.tf, variables.tf)"]
    end

    subgraph "Reusable Modules"
        M_app["App Module (main.tf, outputs.tf, variables.tf)"]
        M_db["DB Module (main.tf, outputs.tf, variables.tf)"]
        M_queue["Queue Module (main.tf, outputs.tf, variables.tf)"]
    end

    M_notifier["Notifier Module (com sub-module)"]

    subgraph "Automation & Tools"
        T_cicd["CI/CD & Versioning (.travis.yml, .terraform-version)"]
        T_tools["Supporting Tools (package.json, install_terraform.sh, index.js)"]
    end

    %% Environment to Modules Dependencies
    E_com -->|"uses"| M_app
    E_com -->|"uses"| M_db
    E_com -->|"uses"| M_queue
    E_com -->|"uses"| M_notifier

    E_pre -->|"uses"| M_app
    E_pre -->|"uses"| M_db
    E_pre -->|"uses"| M_queue

    E_pro -->|"uses"| M_app
    E_pro -->|"uses"| M_db
    E_pro -->|"uses"| M_queue

    E_rev -->|"uses"| M_app
    E_rev -->|"uses"| M_db
    E_rev -->|"uses"| M_queue

    %% Feedback from Environment-Specific Sub-module to Environment
    M_notifier -->|"outputs"| E_com

    %% CI/CD and Tools Integration with Environments
    T_cicd -->|"triggers"| E_com
    T_cicd -->|"triggers"| E_pre
    T_cicd -->|"triggers"| E_pro
    T_cicd -->|"triggers"| E_rev

    T_tools -->|"supports"| E_com
    T_tools -->|"supports"| E_pre
    T_tools -->|"supports"| E_pro
    T_tools -->|"supports"| E_rev

    %% Styles
    classDef environment fill:#FFCCCC,stroke:#990000,stroke-width:2px;
    classDef module fill:#CCFFCC,stroke:#009900,stroke-width:2px;
    classDef tool fill:#CCCCFF,stroke:#000099,stroke-width:2px;
    
    class E_com,E_pre,E_pro,E_rev environment;
    class M_app,M_db,M_queue,M_notifier module;
    class T_cicd,T_tools tool;

    %% Click Events
    click E_com "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/environments/com"
    click E_pre "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/environments/pre"
    click E_pro "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/environments/pro"
    click E_rev "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/environments/rev"
    click M_app "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/modules/app"
    click M_db "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/modules/db"
    click M_queue "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/modules/queue"
    click M_notifier "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/tree/main/infrastructure/environments/com/modules/notifier"
    click T_cicd "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/blob/main/.travis.yml"
    click T_tools "https://github.com/marcinkasprowicz/ultimate-terraform-folder-structure/blob/main/package.json"
```
