# prasadhol2001/learn-terraform-circleci architecture

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

- Interactive diagram: https://gitdiagram.com/prasadhol2001/learn-terraform-circleci
- Repository: https://github.com/prasadhol2001/learn-terraform-circleci

## Overview

##### Project type and purpose
- This is an Infrastructure-as-Code (IaC) repository that demonstrates how to automate Terraform runs using CircleCI.
- It contains Terraform configuration (.tf files) plus a CircleCI pipeline definition (.circleci/config.yml).

##### File structure
- Top-level directories and files:
- .circleci/config.yml → CI pipeline definition
- *.tf (main.tf, variables.tf, outputs.tf, terraform.tf, terraform.tfvars) → Terraform configuration and variable definitions
- assets/index.html → sample static asset deployed by Terraform
- .gitignore, LICENSE, README.md → meta files
- No “frontend” or “backend” code—this is purely an automation/IaC repo.
- The Terraform files define resources (likely a static website hosting environment) and backends; the CircleCI config defines the workflow (init, plan, apply).

##### README for additional insights
- The README confirms this is a companion repo for a HashiCorp Learn tutorial on Terraform + CircleCI automation.

##### Main components
a. Version Control System (VCS)
- GitHub (or other Git host) where the repo lives
b. Continuous Integration (CI) Platform
- CircleCI, with a defined pipeline that runs on push
c. Terraform CLI & Configuration
- main.tf, variables.tf, etc.
d. Terraform State Backend
- Remote state (e.g., S3 backend or Terraform Cloud)—configured in terraform.tf
e. Target Cloud Provider
- AWS, Azure, GCP, etc. (as specified in main.tf) where resources get created
f. Sample Static Content
- assets/index.html deployed to the provisioned infrastructure

##### Relationships and data flows
1. Developer pushes commit → triggers CircleCI pipeline
2. CircleCI “checkout” step retrieves the Terraform code
3. CircleCI runs “terraform init” (configures backend)
4. CircleCI runs “terraform plan” (reads state, computes diff)
5. CircleCI runs “terraform apply” (provisions/updates resources in the cloud)
6. Terraform state is stored in the remote backend for future runs
7. Deployed infrastructure (e.g., an S3 bucket/CloudFront or equivalent) hosts the index.html asset

##### Architectural patterns and design principles
- CI/CD for IaC: Everything is automated; no manual runs.
- Immutable infrastructure: Changes go through version control and review.
- Remote state locking: Prevents concurrent applies.
- Clear separation of concerns: Repo = code; CircleCI = orchestration; cloud = runtime.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer and VCS
    Dev["Developer Workstation"]:::blue
    GitHub["GitHub Repo"]:::blue
    Dev -->|"git push"| GitHub

    %% CI/CD Layer
    GitHub -->|"webhook"| CircleCI
    subgraph "CircleCI Pipeline"
        direction TB
        Checkout["Checkout Code"]:::green
        Init["terraform init"]:::green
        Plan["terraform plan"]:::green
        Apply["terraform apply"]:::green
    end
    CircleCI["CircleCI Pipeline"]:::green
    CircleCI --> Checkout
    Checkout --> Init
    Init --> Plan
    Plan --> Apply

    %% IaC Components
    subgraph "Terraform Configuration" 
        direction TB
        MainTF["main.tf"]:::orange
        VariablesTF["variables.tf"]:::orange
        OutputsTF["outputs.tf"]:::orange
        BackendTF["terraform.tf"]:::orange
        TFVars["terraform.tfvars"]:::orange
        LockFile[".terraform.lock.hcl"]:::orange
        Asset["assets/index.html"]:::orange
    end
    Checkout --> MainTF
    Checkout --> VariablesTF
    Checkout --> OutputsTF
    Checkout --> BackendTF
    Checkout --> TFVars
    Checkout --> LockFile
    Checkout --> Asset

    %% State Backend and Cloud
    StateBackend["Remote State Backend"]:::gray
    CloudProvider["Cloud Provider Resources\n(Static Website Hosting)"]:::gray

    Init -->|"configure backend"| StateBackend
    Apply -->|"store state"| StateBackend
    Apply -->|"provision infra"| CloudProvider

    %% Click Events
    click CircleCI "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/.circleci/config.yml"
    click MainTF "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/main.tf"
    click VariablesTF "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/variables.tf"
    click OutputsTF "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/outputs.tf"
    click BackendTF "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/terraform.tf"
    click TFVars "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/terraform.tfvars"
    click LockFile "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/.terraform.lock.hcl"
    click Asset "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/assets/index.html"
    click GitHub "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/.gitignore"
    click README "https://github.com/prasadhol2001/learn-terraform-circleci/blob/main/README.md"
    click LICENSE "https://github.com/prasadhol2001/learn-terraform-circleci/tree/main/LICENSE"

    %% Styles
    classDef blue fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef green fill:#E6FFEA,stroke:#28A745,color:#28A745;
    classDef orange fill:#FFF4E5,stroke:#D97706,color:#D97706;
    classDef gray fill:#F0F0F0,stroke:#6B7280,color:#6B7280;
```
