# srekoc/cloud-infra architecture

> Architecture diagram of the GitHub repository srekoc/cloud-infra, 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/srekoc/cloud-infra
- Repository: https://github.com/srekoc/cloud-infra

## Overview

##### Project type and purpose
- This is an infrastructure‐as‐code/devops toolchain focused on creating and cloning VMware vSphere VM images.
- It uses Packer to build a golden VM template and Terraform to provision and configure VMs in a private cloud.
- It also includes Python and shell scripts for post-provisioning operations (DNS registration via Verdad, reboot/reset via bastion hosts) and a “testing” folder for validating Terraform & Python modules.

##### File structure
- Top-level folders:
- packer/ – Packer JSON definitions and kickstart (ks.cfg)
- terraform/ – Terraform state, variables, main.tf, provider plugins
- python/ – post_processor.py and its README (REST API integration code)
- shell/ – helper scripts (activate, reset_vms)
- testing/ – sample .tf, .py and test harness + Terraform lock & providers
- Key config files:
- packer/centos-vsphere.json (image build spec)
- terraform/main.tf, variables.tf, terraform.tfvars (infrastructure spec)
- The presence of “.terraform” plugin directories indicates local provider plugins for vsphere, null, random.

##### README for additional insights
- Workflow:
1) Run Packer to create a “gold-template” VM image on vSphere.
2) Run Terraform to clone VMs from that template using the vSphere provider, assign IPs from IPAM, configure network.
3) Post-provisioning: run Python scripts to register in Verdad, then SSH to bastion for “central-push”, then reset/reboot VMs via shell scripts.
- Key dependencies: Python3 libs (urllib3, requests), Packer, Terraform CLI, vsphere creds, Verdad creds, IPAM service.

##### Essential architectural elements
- Terraform state file currently local (future enhancement: remote backend).
- Use of provider plugins under terraform/.terraform/providers.
- Detail the variable flow: .tfvars → main.tf/variables.tf → packer JSON variables.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Developer / CI"
        CLI["Developer Workstation / CI (CLI)"]:::external
    end

    subgraph "Packer Build" 
        PB["Packer Builder Module"]:::iac
        KS["Packer Kickstart Script"]:::iac
    end

    subgraph "Terraform Provision"
        TF["Terraform Infrastructure Module"]:::iac
        TV["variables.tf / terraform.tfvars"]:::iac
        TS[(Terraform State Files)]:::iac
        TPL["Terraform Provider Plugins"]:::iac
    end

    subgraph "Post-Provision Automation"
        PY["Python Post-Processor"]:::scripts
        SH1["shell/activate"]:::scripts
        SH2["shell/reset_vms"]:::scripts
    end

    subgraph ExternalServices
        VS["vSphere API"]:::external
        IPAM["IPAM Service"]:::external
        VER["Verdad REST API"]:::external
        BH["Bastion Host"]:::external
        TVM["Target VMs"]:::external
    end

    subgraph "Testing Harness"
        THTF["testing/main.tf"]:::testing
        THPY["testing/sample.py, sample-1.py, sample-2.py, test.py"]:::testing
        THDATA["testing/a.json, b.json"]:::testing
        THPL["testing/.terraform/providers"]:::testing
        THLOCK["testing/.terraform.lock.hcl"]:::testing
    end

    CLI -->|"packer build"| PB
    CLI -->|"terraform init/plan/apply"| TF
    PB -->|"create VM template"| VS
    TF -->|"clone VM from template"| VS
    TF -->|"assign IP"| IPAM
    TF -->|"local-exec: invoke post_processor"| PY
    PY -->|"POST /api/vm/register"| VER
    SH2 -->|"SSH"| BH
    BH -->|"reset/reboot VMs"| TVM

    THTF -->|"validate Terraform"| TF
    THPY -->|"validate Python modules"| PY

    classDef iac fill:#b2f5b6,stroke:#2f855a
    classDef external fill:#bee3f8,stroke:#2b6cb0
    classDef scripts fill:#fefcbf,stroke:#d69e2e
    classDef testing fill:#e2e8f0,stroke:#4a5568

    click PB "https://github.com/srekoc/cloud-infra/blob/main/packer/centos-vsphere.json"
    click KS "https://github.com/srekoc/cloud-infra/blob/main/packer/ks.cfg"
    click TF "https://github.com/srekoc/cloud-infra/blob/main/terraform/main.tf"
    click TV "https://github.com/srekoc/cloud-infra/blob/main/terraform/variables.tf"
    click TV "https://github.com/srekoc/cloud-infra/blob/main/terraform/terraform.tfvars"
    click TS "https://github.com/srekoc/cloud-infra/blob/main/terraform/terraform.tfstate"
    click TS "https://github.com/srekoc/cloud-infra/blob/main/terraform/terraform.tfstate.backup"
    click TPL "https://github.com/srekoc/cloud-infra/tree/main/terraform/.terraform/providers"
    click PY "https://github.com/srekoc/cloud-infra/blob/main/python/post_processor.py"
    click PY "https://github.com/srekoc/cloud-infra/blob/main/python/README.md"
    click SH1 "https://github.com/srekoc/cloud-infra/tree/main/shell/activate"
    click SH2 "https://github.com/srekoc/cloud-infra/tree/main/shell/reset_vms"
    click THTF "https://github.com/srekoc/cloud-infra/blob/main/testing/main.tf"
    click THPY "https://github.com/srekoc/cloud-infra/blob/main/testing/sample.py"
    click THPY "https://github.com/srekoc/cloud-infra/blob/main/testing/sample-1.py"
    click THPY "https://github.com/srekoc/cloud-infra/blob/main/testing/sample-2.py"
    click THPY "https://github.com/srekoc/cloud-infra/blob/main/testing/test.py"
    click THDATA "https://github.com/srekoc/cloud-infra/blob/main/testing/a.json"
    click THDATA "https://github.com/srekoc/cloud-infra/blob/main/testing/b.json"
    click THPL "https://github.com/srekoc/cloud-infra/tree/main/testing/.terraform/providers"
    click THLOCK "https://github.com/srekoc/cloud-infra/blob/main/testing/.terraform.lock.hcl"
```
