# dushyantkhobragade/terraform_foreman_vm_creation architecture

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

- Interactive diagram: https://gitdiagram.com/dushyantkhobragade/terraform_foreman_vm_creation
- Repository: https://github.com/dushyantkhobragade/terraform_foreman_vm_creation

## Overview

##### Project Type and Purpose
- This is an IaC/automation project built with Terraform.
- Its sole purpose is to read VM metadata from a CSV file (vms.csv) and automate VM creation in Foreman via the terraform-coop/foreman provider.

##### File Structure and README
- Top-level files:
- main.tf – Terraform configuration (provider, credentials, CSV path, resources)
- vms.csv – Input metadata for each VM (FQDN, hostgroup ID, CPU count, memory)
- README.md – Describes prerequisites, Terraform workflow, and provider usage
- No nested modules or separate frontend/backend directories imply a single-component automation workflow.

##### Main Components
a. Developer Workstation
- Contains Terraform CLI, main.tf, and vms.csv
- Runs terraform init/validate/plan/apply
b. Terraform Core
- Reads main.tf & vms.csv
- Manages plugin lifecycle, state file, and execution plan
c. Foreman Provider Plugin
- terraform-coop/foreman/0.7.0, downloaded from the public registry during terraform init
d. Foreman Server
- Exposes API endpoints for provisioning hosts
- Requires credentials (username/password or token)
- Hosts network services (DNS, DHCP, PXE)
e. Public Terraform Registry
- Source for provider plugin
f. CSV Metadata Source (vms.csv)
- Tabular VM definitions used by the Terraform resource block

##### Relationships and Data Flows
- Terraform CLI → (init) → Public Registry: downloads foreman provider plugin
- Terraform CLI ← (reads) main.tf & vms.csv
- Terraform Core → (HTTP/HTTPS API calls) → Foreman Server
- Authentication with credentials
- Create VM resources in specified hostgroups
- Foreman Server → (response) → Terraform Core
- Terraform Core → (state file) → Local filesystem (for tracking created resources)

##### Architectural Patterns and Principles
- Modular separation: Terraform Core vs. Provider Plugin vs. Target System
- Declarative resource management: vms.csv + main.tf define desired state
- Idempotence: Terraform plan/apply cycles ensure predictable provisioning

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Workstation and Local Files
    subgraph "Developer Workstation"
        WORK["Developer Workstation"]:::dev
        subgraph "Local Files"
            MAIN_TF["main.tf"]:::file
            VMS_CSV["vms.csv"]:::file
            README["README.md"]:::file
        end
    end

    %% Terraform Core & CLI
    TERRAFORM["Terraform Core & CLI"]:::core

    %% Provider Plugin and Registry
    REGISTRY["Public Terraform Registry"]:::registry
    PLUGIN["Foreman Provider Plugin\n(terraform-coop/foreman)"]:::plugin

    %% Foreman Server
    FOREMAN["Foreman Server\n(API, DHCP, DNS, PXE)"]:::server

    %% Local State
    STATE["Local State File"]:::file

    %% Connections
    WORK -->|"run init/validate/plan/apply"| TERRAFORM
    WORK -->|reads| MAIN_TF
    WORK -->|reads| VMS_CSV
    WORK -->|docs| README

    TERRAFORM -->|"init: download provider"| REGISTRY
    REGISTRY -->|"provides plugin binary"| PLUGIN
    TERRAFORM -->|"load plugin"| PLUGIN

    TERRAFORM -->|"HTTPS API calls"| FOREMAN
    FOREMAN -->|"API responses"| TERRAFORM

    TERRAFORM -->|"write state"| STATE

    %% Click Events
    click MAIN_TF "https://github.com/dushyantkhobragade/terraform_foreman_vm_creation/blob/main/main.tf"
    click VMS_CSV "https://github.com/dushyantkhobragade/terraform_foreman_vm_creation/blob/main/vms.csv"
    click README "https://github.com/dushyantkhobragade/terraform_foreman_vm_creation/blob/main/README.md"

    %% Styles
    classDef dev fill:#D0E6FF,stroke:#036,stroke-width:2px
    classDef core fill:#D0F0D0,stroke:#070,stroke-width:2px
    classDef plugin fill:#FFE4B5,stroke:#F80,stroke-width:2px
    classDef registry fill:#E0E0E0,stroke:#888,stroke-width:2px
    classDef server fill:#F4E1FF,stroke:#A0A,stroke-width:2px
    classDef file fill:#FFFACD,stroke:#DAA520,stroke-width:2px
```
