# levetty/terraform-aws-cloudbase architecture

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

- Interactive diagram: https://gitdiagram.com/levetty/terraform-aws-cloudbase
- Repository: https://github.com/levetty/terraform-aws-cloudbase

## Overview

##### Main Components
- Terraform Root Module: Represented by the top-level files (main.tf, variables.tf, versions.tf, README.md, LICENSE). This is the entry point for setting module configuration.
- Submodules: In particular, the “vm_scan” submodule inside the module folder. This submodule handles resources (e.g., IAM and KMS configurations) specific to virtual machine scanning.
- Policies: A directory containing JSON files for each scanning type (container_scan, vm_scan, lambda_scan, and various CSPM policies). These represent the policy definitions that are attached to the IAM roles.
- User Configuration Interface: Illustrated in the README examples, where the user specifies various booleans (allow_container_scan_permissions, allow_vm_scan_permissions, etc.) that control which policies are applied.

##### Relationships and Interactions
- The Root Module accepts user inputs and variables that determine what scan permissions are enabled.
- It then integrates with the VM Scan Submodule if VM scan permissions are toggled on. The submodule defines resources (as seen by the presence of iam.tf, kms.tf, etc.) that are specific to VM scanning.
- The module leverages JSON policy definitions stored in the policies directory. These are attached to the IAM roles created in the module.
- Outputs (like cloudbase_role_arn) provide the resulting IAM role ARN back to the user, connecting the configured module to the consumer (e.g., Cloudbase console).

##### Architectural Patterns
- Modularization: The use of submodules (e.g., vm_scan) shows a well-separated and modular design.
- Declarative Infrastructure: All components are defined in Terraform with configuration files and policy JSON files.
- Parameterization: The module uses variables to customize behavior, allowing extensive configuration and reuse.

##### Relevant Technologies
- Terraform: As the core technology, with HCL for configuration.
- AWS Services: IAM (for role creation and policy attachments), KMS (used in the vm_scan module for encryption), and likely other services implicitly used by scanning (ECR for container scanning, EC2 snapshots for VM scans, Lambda functions, CloudTrail).
- JSON: For policy definitions.

##### Instructing the Principal Software Engineer
- Clear Labels: Each component (Root Module, VM Scan Module, Policies, IAM Role, KMS configuration).

## Diagram (Mermaid)

```mermaid
flowchart TD
    UCI["User Configuration Interface<br/>(variables in README)"]:::config
    TCM["Terraform Cloudbase Module<br/>(main.tf, variables.tf, versions.tf, README.md, LICENSE)"]:::module
    VMS["VM Scan Submodule<br/>(iam.tf, kms.tf, locals.tf, variables.tf, README.md)"]:::module
    POL["Policies (JSON Files)<br/>(container_scan.json,<br/>cspm_read_0.json,<br/>cspm_read_1.json,<br/>cspm_read_2.json,<br/>cspm_read_3.json,<br/>lambda_scan.json,<br/>vm_scan.json)"]:::json
    IAM["IAM Role (cloudbase_role_arn)"]:::aws
    CBC["Cloudbase Console"]:::aws

    UCI -->|"configures"| TCM
    TCM -->|"if allow_vm_scan_permissions"| VMS
    TCM -->|"includes policies"| POL
    VMS --> IAM
    POL --> IAM
    TCM --> IAM
    IAM -->|"provides ARN to"| CBC

    click UCI "https://github.com/levetty/terraform-aws-cloudbase/blob/main/README.md"
    click TCM "https://github.com/levetty/terraform-aws-cloudbase/blob/main/main.tf"
    click VMS "https://github.com/levetty/terraform-aws-cloudbase/tree/main/module/vm_scan"
    click POL "https://github.com/levetty/terraform-aws-cloudbase/tree/main/policies"

    classDef config fill:#bbdefb,stroke:#0d47a1,stroke-width:2px,color:#0d47a1;
    classDef module fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px,color:#1b5e20;
    classDef json fill:#fff9c4,stroke:#f57f17,stroke-width:2px,color:#f57f17;
    classDef aws fill:#ffe0b2,stroke:#e65100,stroke-width:2px,color:#e65100;
```
