# delgadoroberto/terraform-s3-security-lab architecture

> Architecture diagram of the GitHub repository delgadoroberto/terraform-s3-security-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/delgadoroberto/terraform-s3-security-lab
- Repository: https://github.com/delgadoroberto/terraform-s3-security-lab

## Overview

1. **What this repository is**
   - This is a **local AWS S3 security lab**, not a production application.
   - The architecture centers on **provisioning a single S3 bucket with Terraform**, but targeting **LocalStack** so the AWS APIs are emulated locally.

2. **Primary control plane**
   - The `terraform/` directory is the main infrastructure definition boundary.
   - `main.tf`, `variables.tf`, `terraform.tfvars`, `outputs.tf`, and `versions.tf` define the desired S3 configuration, parameterization, provider/runtime constraints, and exported identifiers for verification.

3. **Execution/runtime environment**
   - **Docker** runs **LocalStack**, which acts as the AWS-compatible endpoint.
   - Terraform and the AWS CLI are pointed at LocalStack instead of real AWS, using dummy credentials and the local endpoint URL.
   - This makes the whole lab self-contained and repeatable on a developer machine.

4. **Provisioning flow**
   - The intended flow is: edit Terraform variables → run `terraform init/plan/apply` → Terraform calls the S3 API through LocalStack → LocalStack creates the bucket and related settings.
   - The Terraform outputs likely provide the bucket name or other identifiers needed for verification.

5. **Verification and inspection path**
   - After provisioning, the **AWS CLI** is used against the LocalStack endpoint to confirm the bucket exists and inspect its state.
   - This is the operational verification boundary: Terraform declares the desired state, and AWS CLI checks the realized state.

6. **Security validation subsystem**
   - Two IaC scanners validate the Terraform code itself:
     - **Checkov** for policy and misconfiguration checks
     - **Trivy config** for IaC/security scanning
   - Their reports are stored under `scans/`, making the repo both a lab and an artifact collection point.

7. **Audit automation**
   - `scripts/audit_s3.sh` is a Bash-based audit step that checks S3 security posture from the outside, likely focusing on controls such as versioning and public access behavior.
   - This script bridges infrastructure provisioning and security validation by testing the deployed resource, not just the code.

8. **Security and compliance findings**
   - The `findings/` folder captures discovered issues and remediation notes.
   - `findings/insecure-config.md` and `findings/remediation.md` suggest the repo is used to document misconfigurations and how they were fixed, which is important for the lab’s learning loop.

9. **CI / automation boundary**
   - `.github/workflows/security-pipeline.yml` shows there is an automation layer in GitHub Actions.
   - Its role is likely to run scans and validations consistently in CI, turning the lab into a repeatable DevSecOps workflow rather than only a manual exercise.

10. **Documentation and learning artifacts**
   - `docs/lessons-learned.md` and the architecture diagram under `architecture/` are supporting artifacts.
   - These do not participate in runtime provisioning, but they document decisions, outcomes, and the intended system layout.

11. **Data flow summary**
   - Human edits Terraform config → Terraform provisions via LocalStack → AWS CLI and the audit script verify the bucket → Checkov/Trivy analyze the Terraform code → results are captured in `scans/` and `findings/`.
   - The key boundary is between **static IaC analysis** and **runtime resource validation**.

12. **Architectural constraints that matter**
   - The system is intentionally **local-first** and **AWS-emulated**, so there is no dependency on live cloud infrastructure.
   - Security controls emphasized in the lab are S3-focused: **versioning**, **public access restrictions**, and general **misconfiguration detection**.
   - The architecture is built for **learning, testing, and validation**, not for hosting user-facing workloads.

Main entry points: [`terraform/main.tf`](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/main.tf) (Main stack), [`.github/workflows/security-pipeline.yml`](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/.github/workflows/security-pipeline.yml) (CI pipeline), [`scans/checkov-report.txt`](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scans/checkov-report.txt) (Checkov), [`scans/trivy-report.txt`](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scans/trivy-report.txt) (Trivy config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_terraform["Terraform lab"]
  node_n_terraform_main["Main stack<br/>terraform root<br/>[main.tf]"]
  node_n_terraform_vars["Variables<br/>terraform inputs<br/>[variables.tf]"]
  node_n_terraform_tfvars["Lab values<br/>terraform values<br/>[terraform.tfvars]"]
  node_n_terraform_outputs["Outputs<br/>terraform exports<br/>[outputs.tf]"]
  node_n_terraform_versions["Versions<br/>terraform runtime<br/>[versions.tf]"]
end

subgraph group_g_runtime["Local runtime"]
  node_n_localstack["LocalStack<br/>aws emulator"]
  node_n_aws_cli["AWS CLI<br/>verifier"]
end

subgraph group_g_validation["Security validation"]
  node_n_audit_script["Audit script<br/>bash audit<br/>[audit_s3.sh]"]
  node_n_checkov["Checkov<br/>iac scanner<br/>[checkov-report.txt]"]
  node_n_trivy["Trivy config<br/>iac scanner<br/>[trivy-report.txt]"]
  node_n_findings_insecure["Issues<br/>finding note<br/>[insecure-config.md]"]
  node_n_findings_remediation["Remediation<br/>finding note<br/>[remediation.md]"]
end

subgraph group_g_ci["Automation"]
  node_n_github_actions["CI pipeline<br/>github actions"]
end

subgraph group_g_docs["Docs and artifacts"]
  node_n_lessons["Lessons<br/>documentation<br/>[lessons-learned.md]"]
  node_n_architecture_diagram["Diagram<br/>architecture artifact"]
end

node_n_terraform_versions -->|"pins"| node_n_terraform_main
node_n_terraform_vars -->|"feeds"| node_n_terraform_main
node_n_terraform_tfvars -->|"instantiates"| node_n_terraform_vars
node_n_terraform_main -->|"provisions via"| node_n_localstack
node_n_terraform_outputs -->|"verifies with"| node_n_aws_cli
node_n_localstack -->|"serves"| node_n_aws_cli
node_n_audit_script -->|"checks"| node_n_localstack
node_n_checkov -->|"analyzes"| node_n_terraform_main
node_n_trivy -->|"analyzes"| node_n_terraform_main
node_n_checkov -->|"records"| node_n_findings_insecure
node_n_trivy -->|"records"| node_n_findings_insecure
node_n_findings_insecure -->|"leads to"| node_n_findings_remediation
node_n_github_actions -->|"runs"| node_n_checkov
node_n_github_actions -->|"runs"| node_n_trivy
node_n_github_actions -->|"runs"| node_n_audit_script
node_n_lessons -->|"documents"| node_n_findings_remediation
node_n_architecture_diagram -->|"depicts"| node_n_terraform_main
node_n_architecture_diagram -->|"depicts"| node_n_localstack

click node_n_terraform_main "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/main.tf"
click node_n_terraform_vars "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/variables.tf"
click node_n_terraform_tfvars "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/terraform.tfvars"
click node_n_terraform_outputs "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/outputs.tf"
click node_n_terraform_versions "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/versions.tf"
click node_n_audit_script "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scripts/audit_s3.sh"
click node_n_checkov "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scans/checkov-report.txt"
click node_n_trivy "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scans/trivy-report.txt"
click node_n_findings_insecure "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/findings/insecure-config.md"
click node_n_findings_remediation "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/findings/remediation.md"
click node_n_github_actions "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/.github/workflows/security-pipeline.yml"
click node_n_lessons "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/docs/lessons-learned.md"
click node_n_architecture_diagram "https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/architecture/terraform-s3-security-lab-Diagram.drawio.drawio"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_terraform_main,node_n_terraform_vars,node_n_terraform_tfvars,node_n_terraform_outputs,node_n_terraform_versions toneBlue
class node_n_localstack,node_n_aws_cli toneAmber
class node_n_audit_script,node_n_checkov,node_n_trivy,node_n_findings_insecure,node_n_findings_remediation toneMint
class node_n_github_actions toneRose
class node_n_lessons,node_n_architecture_diagram toneIndigo
```

## Components

### Terraform lab

Main infrastructure boundary for the local S3 provisioning flow.

- [Main stack](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/main.tf): terraform root · Defines the S3 bucket and related infrastructure resources. · `terraform/main.tf`
- [Variables](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/variables.tf): terraform inputs · Parameterizes bucket and environment settings. · `terraform/variables.tf`
- [Lab values](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/terraform.tfvars): terraform values · Concrete local lab inputs used for planning and apply. · `terraform/terraform.tfvars`
- [Outputs](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/outputs.tf): terraform exports · Exports bucket identifiers and other verification values. · `terraform/outputs.tf`
- [Versions](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/terraform/versions.tf): terraform runtime · Pins provider and Terraform version constraints. · `terraform/versions.tf`

### Local runtime

LocalStack and CLI-based runtime used to emulate AWS and verify resources.

- **LocalStack**: aws emulator · Local AWS-compatible endpoint that receives Terraform API calls.
- **AWS CLI**: verifier · Inspects the emulated S3 state after provisioning.

### Security validation

Static scans, runtime audits, and captured findings.

- [Audit script](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scripts/audit_s3.sh): bash audit · Checks deployed S3 security posture from the outside. · `scripts/audit_s3.sh`
- [Checkov](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scans/checkov-report.txt): iac scanner · Static policy and misconfiguration analysis for Terraform. · `scans/checkov-report.txt`
- [Trivy config](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/scans/trivy-report.txt): iac scanner · IaC security scanning and configuration analysis. · `scans/trivy-report.txt`
- [Issues](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/findings/insecure-config.md): finding note · Captured insecure configuration observations. · `findings/insecure-config.md`
- [Remediation](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/findings/remediation.md): finding note · Documented fixes and recovery notes. · `findings/remediation.md`

### Automation

Repository automation that runs validation in GitHub Actions.

- [CI pipeline](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/.github/workflows/security-pipeline.yml): github actions · Automates scans and validation in GitHub Actions. · `.github/workflows/security-pipeline.yml`

### Docs and artifacts

Supporting documentation and architecture artifacts.

- [Lessons](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/docs/lessons-learned.md): documentation · Summarizes outcomes and takeaways from the lab. · `docs/lessons-learned.md`
- [Diagram](https://github.com/delgadoroberto/terraform-s3-security-lab/blob/main/architecture/terraform-s3-security-lab-Diagram.drawio.drawio): architecture artifact · Visual reference for the repository layout and flow. · `architecture/terraform-s3-security-lab-Diagram.drawio.drawio`

## Connections

- Versions → Main stack: pins · Constrains the infrastructure stack runtime and provider versions.
- Variables → Main stack: feeds · Provides configurable inputs to the Terraform stack.
- Lab values → Variables: instantiates · Supplies local lab values for the declared variables.
- Main stack → LocalStack: provisions via · Terraform targets the emulated AWS endpoint instead of real AWS.
- Outputs → AWS CLI: verifies with · Exports identifiers used to inspect the created bucket.
- LocalStack → AWS CLI: serves · AWS CLI queries the same local AWS-compatible endpoint.
- Audit script → LocalStack: checks · Runs external security checks against the deployed S3 resource.
- Checkov → Main stack: analyzes · Scans the Terraform definition for policy and misconfiguration issues.
- Trivy config → Main stack: analyzes · Scans the Terraform configuration for security issues.
- Checkov → Issues: records · Captured issues are summarized in findings documentation.
- Trivy config → Issues: records · Captured issues are summarized in findings documentation.
- Issues → Remediation: leads to · Observed issues inform remediation notes.
- CI pipeline → Checkov: runs · CI automates static IaC scanning.
- CI pipeline → Trivy config: runs · CI automates IaC security scanning.
- CI pipeline → Audit script: runs · CI can execute runtime security checks as part of the pipeline.
- Lessons → Remediation: documents · Lessons learned are tied to remediation outcomes.
- Diagram → Main stack: depicts · Diagram documents the main provisioning boundary.
- Diagram → LocalStack: depicts · Diagram documents the local emulation runtime.
