# bridgecrewio/terragoat architecture

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

- Interactive diagram: https://gitdiagram.com/bridgecrewio/terragoat
- Repository: https://github.com/bridgecrewio/terragoat

## Overview

##### Project Overview and Main Components
- TerraGoat as an infrastructure-as-code (IaC) repository built with Terraform. Its primary purpose is to serve as a learning platform to expose and test misconfiguration vulnerabilities across major cloud providers.
- Main components include:
– Terraform configuration modules for multiple clouds (AWS, Azure, GCP, Alibaba Cloud, and Oracle).
– The “packages” directory (including Node.js examples for testing, additional configurations such as pom.xml and requirements.txt) which provide supplementary providers, tests, or sample dependencies.
– CI/CD pipelines, as evident from the .github and gitlabci directories, which automate builds, pull requests, and static code analysis (via workflows that include Semgrep and Bridgecrew badges).
– Infrastructure resource templates that simulate various misconfigurations (e.g., vulnerable AWS RDS, EC2, load balancers, and security groups with intentional vulnerabilities).

##### Architectural Patterns and Structural Analysis
- The file tree is organized into distinct top-level directories:
– “terraform”: Contains separate subdirectories for each cloud provider, where each one holds the Terraform modules configuring specific cloud resources.
– “packages”: Contains additional code examples and configurations that may complement or test the Terraform configurations.
– “.github” and “gitlabci”: Define deployment, build, and security-scanning pipelines.
- Recognize that the organization implies a multi-cloud, modular design where each cloud provider’s infrastructure is deployed by independently configured Terraform modules.
- The overall pattern hints at a service-based architecture where different “stacks” are created (for instance, multiple AWS stacks can be deployed) and integrated testing or analysis tools (like Checkov and Bridgecrew) are applied.

– Azure: Represent resources deployed via “terraform/azure”, such as Virtual Machines, App Services, AKS clusters, SQL Servers, Key Vaults, and Application Gateways.
– AliCloud and Oracle: Represent additional resource modules (from “terraform/alicloud” and “terraform/oracle”) including buckets, RDS-equivalent databases, and networking configurations.
- A CI/CD pipeline area which spans across the whole project (indicating where GitHub Actions, GitLab CI, and security scanning integrations such as Semgrep and Bridgecrew are applied).

##### Relationships and Data Flows
– From the CI/CD pipeline (triggered by code commits in the repository) to each Terraform module.
– From Terraform executing deployment to cloud resources.
- That external tools (like Checkov scanning or Bridgecrew analysis) interact with the infrastructure state by scanning configuration files and deployed resources.

##### Technologies and Specifics to Highlight
- Core technologies: Terraform (version ≥ 0.12), cloud CLIs (aws cli, azure cli), and state management backends (S3 for AWS, Azure Storage for Azure, GCS for GCP).
- If desired, show that there are additional packages (like NodeJS examples in “packages/node”) that run independent tests or serve as client examples.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["TerraGoat IAC Repository (Vulnerable by design)"]:::system

    subgraph "CI/CD Pipelines"
        CI1["GitHub Actions (.github)"]:::cicd
        CI2["GitLab CI (gitlabci)"]:::cicd
        SC["Security Scanning (Semgrep,Bridgecrew)"]:::scan
    end

    TE["Terraform Engine"]:::terraform

    subgraph "Cloud Providers"
        AWS["AWS - (EC2,RDS,ELB,EKS,IAM,Lambda,Elasticsearch)"]:::aws
        AZ["Azure - (VMs,AppServices,AKS,SQL,KeyVault,AppGateways)"]:::azure
        GCP["GCP - (Compute,CloudSQL,GKE,BigQuery,Storage)"]:::gcp
        AL["Alibaba Cloud - (Buckets,RDS-like)"]:::alicloud
        OR["Oracle - (Buckets,Compartments,Data)"]:::oracle
    end

    P["Supplementary Packages (Node.js examples,pom.xml,requirements.txt)"]:::packages

    A --> CI1
    A --> CI2
    A --> SC
    CI1 -->|"triggers"| TE
    CI2 -->|"triggers"| TE
    SC -->|"analyzes"| TE

    TE -->|"deploys"| AWS
    TE -->|"deploys"| AZ
    TE -->|"deploys"| GCP
    TE -->|"deploys"| AL
    TE -->|"deploys"| OR

    P -->|"supplements"| TE

    click AWS "https://github.com/bridgecrewio/terragoat/tree/master/terraform/aws"
    click AZ "https://github.com/bridgecrewio/terragoat/tree/master/terraform/azure"
    click GCP "https://github.com/bridgecrewio/terragoat/tree/master/terraform/gcp"
    click AL "https://github.com/bridgecrewio/terragoat/tree/master/terraform/alicloud"
    click OR "https://github.com/bridgecrewio/terragoat/tree/master/terraform/oracle"
    click P "https://github.com/bridgecrewio/terragoat/tree/master/packages"
    click CI1 "https://github.com/bridgecrewio/terragoat/blob/master/.github"
    click CI2 "https://github.com/bridgecrewio/terragoat/tree/master/gitlabci"

    classDef system fill:#f9f,stroke:#333,stroke-width:2px;
    classDef cicd fill:#bbf,stroke:#333,stroke-width:2px;
    classDef terraform fill:#ccf,stroke:#333,stroke-width:2px;
    classDef aws fill:#ffd1dc,stroke:#333,stroke-width:2px;
    classDef azure fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef gcp fill:#d4efdf,stroke:#333,stroke-width:2px;
    classDef alicloud fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef oracle fill:#fad7a0,stroke:#333,stroke-width:2px;
    classDef packages fill:#e8daef,stroke:#333,stroke-width:2px;
    classDef scan fill:#f5b7b1,stroke:#333,stroke-width:2px;
```
