# sidpalas/devops-directive-terraform-course architecture

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

- Interactive diagram: https://gitdiagram.com/sidpalas/devops-directive-terraform-course
- Repository: https://github.com/sidpalas/devops-directive-terraform-course

## Overview

##### Project type and purpose
- This is not a traditional “app” but a monorepo of Terraform tutorial code. It walks students from basic “hello-world” EC2 provisioning up through variable/outputs, modules, multi-environment management, testing, and CI/CD.
- The ultimate “system” it models is an end-to-end Infrastructure as Code pipeline: Developer → GitHub → Terraform (CLI/Cloud) → AWS (VPC, compute, storage, database, DNS) → Environments (dev/staging/prod) → Tests → CI/CD.

##### File structure
- Top-level:
- .github/workflows/terraform.yml (CI pipeline)
- Directories 01-09 corresponding to progressively advanced Terraform lessons
- Key directories:
- 03-basics/web-app → naive single-instance web app
- 04-variables-and-outputs/web-app → refactored web app with variables & outputs
- 06-organization-and-modules/web-app-module → reusable module defining compute.tf, database.tf, dns.tf, networking.tf, storage.tf
- 07-managing-multiple-environments → two patterns: folder structure per environment and Terraform workspaces
- 08-testing → bash tests, Terratest (Go), deployed environment examples
- 09-developer-workflows → GitHub Actions integration
- Configuration files:
- main.tf, variables.tf, outputs.tf in each example
- terraform.tfvars example files
- .github/workflows/terraform.yml for CI/CD

##### README for additional insights
- Each lesson’s README outlines its goal (evolution of IaC, basics, variables, modules, environments, testing, workflows).

a. Main components
- Developer Workstation (Terraform CLI)
- Source Control (GitHub repository)
- CI/CD (GitHub Actions)
- Terraform Cloud / Remote State Backend (or AWS S3 backend)
- Terraform Modules (web-app-module, consul module)
- AWS Infrastructure:
– VPC & networking
– EC2 Auto Scaling Group (compute.tf)
– Datastore (RDS or DynamoDB via database.tf)
– DNS (Route53 via dns.tf)
– Storage (S3 via storage.tf)
- Environments (dev, staging, production workspaces or folder deployments)
- Testing frameworks (Bash scripts, Terratest)

b. Relationships & interactions
1. Developer pushes code → GitHub
2. GitHub Actions triggers → runs terraform init/plan/apply
3. Terraform uses remote state backend (Terraform Cloud or S3)
4. Terraform calls modules (web-app-module, consul)
5. Modules create AWS resources
6. After apply, test suites run (bash scripts, Terratest)
7. Alerts or feedback loop back to GitHub/Slack (optional)

c. Architectural patterns & principles
- Infrastructure as Code (HCL)
- Module reusability & encapsulation (web-app-module, consul)
- Separation of environments via workspaces or directory structure
- Remote state management for collaboration
- Shift-left testing for infrastructure (unit testing modules, integration tests)
- GitOps/CI-driven deployments

d. Key technologies & frameworks
- Terraform (HCL, v0.12+)
- Terraform Cloud or AWS S3 as state backends
- AWS provider (EC2, RDS, VPC, S3, Route53)
- GitHub Actions for CI/CD
- Bash & Go (Terratest) for tests
- Modular directory layout (06-organization-and-modules)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Layer
    Developer["Developer Workstation\n(Terraform CLI)"]:::developer
    RootReadme["Course Overview\nREADME.md"]:::code

    Developer -->|push code| GitHub["GitHub Repository"]:::code
    GitHub -->|trigger| CICD["CI/CD Pipeline\n(GitHub Actions)"]:::ci
    click CICD "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/.github/workflows/terraform.yml"
    CICD -->|runs terraform| Terraform["Terraform Engine"]:::terraform

    %% State Backend Subgraph
    subgraph "Remote State Backends"
        direction TB
        S3Backend["AWS S3 Backend"]:::terraform
        click S3Backend "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/03-basics/aws-backend/main.tf"
        CloudBackend["Terraform Cloud Backend"]:::terraform
        click CloudBackend "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/03-basics/terraform-cloud-backend/main.tf"
        Terraform -->|"init with remote state"| S3Backend
        Terraform -->|"init with remote state"| CloudBackend
    end

    %% Modules & Examples Subgraph
    subgraph "Terraform Examples & Modules"
        direction TB
        BasicWeb["Basic Web App\n(single EC2)"]:::terraform
        click BasicWeb "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/03-basics/web-app/main.tf"

        VarWeb["Variables & Outputs Web App"]:::terraform
        click VarWeb "https://github.com/sidpalas/devops-directive-terraform-course/tree/main/04-variables-and-outputs/web-app/"

        VarExamples["Variables & Outputs Examples"]:::terraform
        click VarExamples "https://github.com/sidpalas/devops-directive-terraform-course/tree/main/04-variables-and-outputs/examples/"

        ConsulMod["Consul Module"]:::terraform
        click ConsulMod "https://github.com/sidpalas/devops-directive-terraform-course/tree/main/06-organization-and-modules/consul/"

        WebAppMod["Web-App Module"]:::terraform
        click WebAppMod "https://github.com/sidpalas/devops-directive-terraform-course/tree/main/06-organization-and-modules/web-app-module/"

        WebAppUse["Web-App Module Usage"]:::terraform
        click WebAppUse "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/06-organization-and-modules/web-app/main.tf"

        Terraform --> BasicWeb
        Terraform --> VarWeb
        Terraform --> VarExamples
        Terraform --> ConsulMod
        Terraform --> WebAppMod
        Terraform --> WebAppUse
    end

    %% Multi-Environment Patterns
    subgraph "Multi-Environment Patterns" 
        direction TB
        FolderPattern["Folder-Based Environments"]:::terraform
        click FolderPattern "https://github.com/sidpalas/devops-directive-terraform-course/tree/main/07-managing-multiple-environments/file-structure/"

        WorkspacePattern["Workspace-Based Environments"]:::terraform
        click WorkspacePattern "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/07-managing-multiple-environments/workspaces/main.tf"
        
        Terraform --> FolderPattern
        Terraform --> WorkspacePattern
    end

    %% AWS Infrastructure Layer
    subgraph "AWS Infrastructure" 
        direction TB
        Networking["VPC & Networking"]:::aws
        Compute["EC2 Auto Scaling\n(Compute)"]:::aws
        Database["RDS / DynamoDB\n(Database)"]:::aws
        DNS["Route53 DNS"]:::aws
        Storage["S3 Bucket\n(Storage)"]:::aws

        WebAppMod --> Networking
        WebAppMod --> Compute
        WebAppMod --> Database
        WebAppMod --> DNS
        WebAppMod --> Storage
    end

    %% Testing Subgraph
    subgraph "Testing & Validation"
        direction TB
        DeployedEnvs["Deployed Env Examples"]:::ci
        click DeployedEnvs "https://github.com/sidpalas/devops-directive-terraform-course/tree/main/08-testing/deployed/"

        TestModules["Testing Module Example"]:::ci
        click TestModules "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/08-testing/modules/hello-world/instance.tf"

        BashTests["Bash Tests"]:::ci
        click BashTests "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/08-testing/tests/bash/hello_world_test.sh"

        StaticTests["Static Tests"]:::ci
        click StaticTests "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/08-testing/tests/static/README.md"

        Terratest["Terratest (Go)"]:::ci
        click Terratest "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/08-testing/tests/terratest/hello_world_test.go"

        HelloWorldTest["HelloWorld Terraform Example"]:::ci
        click HelloWorldTest "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/08-testing/examples/hello-world/main.tf"

        Terraform -->|apply| DeployedEnvs
        Terraform -->|apply| TestModules
        Terraform -->|apply| BashTests
        Terraform -->|apply| StaticTests
        Terraform -->|apply| Terratest
        Terraform -->|apply| HelloWorldTest
    end

    %% Developer Workflows Documentation
    DevWF["Developer Workflows\n(Documentation)"]:::code
    click DevWF "https://github.com/sidpalas/devops-directive-terraform-course/blob/main/09-developer-workflows/README.md"
    GitHub --> DevWF

    %% Feedback Loop
    DeployedEnvs -->|feedback| GitHub
    BashTests -->|feedback| GitHub
    Terratest -->|feedback| GitHub

    %% Legend / Root
    RootReadme --> Developer

    classDef developer fill:#f9c,stroke:#333,color:#000;
    classDef code fill:#bbf,stroke:#333,color:#000;
    classDef terraform fill:#8f8,stroke:#333,color:#000;
    classDef aws fill:#fc8,stroke:#333,color:#000;
    classDef ci fill:#c8c,stroke:#333,color:#000;
```
