# elichc5/list-gcp-vms architecture

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

- Interactive diagram: https://gitdiagram.com/elichc5/list-gcp-vms
- Repository: https://github.com/elichc5/list-gcp-vms

## Overview

##### Key Components
- Script Component: The main part is the Bash script (named “list-vms-gcp.sh” as noted in the README, even though the file tree shows “list-info-vms.sh”). This component handles iterating over projects, retrieving VM details, and outputting CSV.
- External Dependencies and Tools:
- Google Cloud SDK: Used (via the “gcloud” command) to list VM instances and describe disks.
- jq: Helps parse JSON output from “gcloud.”
- bc: Converts values (like memory in MB to GB).
- Data Output: The CSV file that aggregates the VM data, where each row represents a VM and the disks information are concatenated.
- GCP Projects/Instances: These represent external systems (the source of VM data) over which the script iterates.

##### Relationships and Data Flow
- The script first reads the list of GCP project IDs from a defined array.
- For each project, it calls the “gcloud compute instances list” command to gather VM data.
- When needed, additional “gcloud” commands are used (with proper parameters like “--zone” or “--region”) to retrieve disk details.
- The script processes the JSON output (using jq) and performs calculations (with bc) to format data before writing each VM’s details to a CSV file.
- The data flow runs from the Script Component -> External Tool Commands -> GCP API (via the SDK) -> processed back into the CSV output.

##### Architectural Patterns/Principles
- Modular Scripting: Even though it is a single script, it is structured in distinct phases (project iteration, data collection, processing/formatting, and output).
- Dependency on External Services: The script offloads most heavy-lifting (like listing instances) to the gcloud CLI and, by extension, the GCP infrastructure.
- Command-line Toolchain: Emphasizes the use of Unix/Linux command-line utilities to parse, process, and calculate data.

##### Relevant Technologies
- Bash: The scripting language.
- gcloud (Google Cloud SDK): To interact with GCP.
- jq: JSON processing.
- bc: Mathematical calculations.
- CSV format for output data.

##### Detailed Elements
- Clearly labeled components for:
- Bash Script (“list-vms-gcp.sh” or “list-info-vms.sh”)
- Google Cloud SDK (gcloud)
- External Tools: jq and bc
- GCP Environment (projects and VM resources)
- CSV Output File
- From the Bash Script to the Google Cloud SDK component (labeled “API calls using gcloud”).
- From the Google Cloud SDK to GCP Resources indicating “data retrieval.”
- Annotations to note:
- Any important configuration details such as where project IDs are set.
- Notes on prerequisites (such as required bash environment, google cloud SDK installation, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Local Components
    subgraph "Local Components"
        BS["Bash Script (list-info-vms.sh)"]:::local
        JQ["jq (JSON Processor)"]:::local
        BC["bc (Math Converter)"]:::local
        CSV(("CSV File Output")):::local
        DOC["Project Documentation (README.md)"]:::local
    end

    %% External Systems
    subgraph "External Systems"
        GC["Google Cloud SDK (gcloud)"]:::external
        GCP["GCP Resources (Projects/VMs)"]:::external
    end

    DOC -->|"Updates_BashScript"| BS
    BS -->|"API_calls_using_gcloud"| GC
    GC -->|"data_retrieval"| GCP
    BS -->|"process_JSON_with_jq"| JQ
    BS -->|"calculate_conversions_with_bc"| BC
    BS -->|"write_data_to_CSV"| CSV

    %% Styles
    classDef local fill:#d1e8e2,stroke:#0b3d91,stroke-width:2px;
    classDef external fill:#fcebb6,stroke:#b22222,stroke-width:2px;

    %% Click Events
    click BS "https://github.com/elichc5/list-gcp-vms/blob/main/list-info-vms.sh"
    click DOC "https://github.com/elichc5/list-gcp-vms/blob/main/README.md"
```
