# abednahouli/terraform_seed architecture

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

- Interactive diagram: https://gitdiagram.com/abednahouli/terraform_seed
- Repository: https://github.com/abednahouli/terraform_seed

## Overview

##### Main Components
- Terraform Configuration: Files like main.tf, provider.tf, variables.tf, outputs.tf, and terraform.tfvars.example.md form the core of the infrastructure provisioning. They define resources such as the DigitalOcean droplet and firewall.
- Python Management Script: The manage_terraform.py script acts as a wrapper to initialize, apply, and destroy Terraform configurations. It is also responsible for updating the Ansible inventory file.
- Ansible Configuration: The setup.yml playbook and ansible_vars_example.yml (to be copied as ansible_vars.yml) represent the configuration management side for setting up the web server.
- Ansible Inventory: The dynamic inventory.ini file (updated automatically) lists the target hosts (the new droplet) for Ansible to work with.
- External Services & Dependencies: DigitalOcean as the cloud provider, along with dependencies like Terraform, Ansible, and Python, which are prerequisites for running the project.

##### Relationships and Interactions
- The Terraform component interacts with the DigitalOcean API to provision infrastructure (droplets and firewall rules).
- Once infrastructure is provisioned, the manage_terraform.py script updates the Ansible inventory (inventory.ini) with the IP address of the new droplet.
- The Ansible playbook (setup.yml) then connects to the droplet using SSH (leveraging the updated inventory) to configure the server (installing/configuring Nginx and MySQL).
- The system thus flows from infrastructure provisioning (Terraform) → inventory update (Python script) → configuration management (Ansible).

##### Architectural Patterns and Design Principles
- Infrastructure as Code (IaC): The use of Terraform demonstrates declarative resource provisioning.
- Configuration Management: Ansible automates server configuration post-provisioning.
- Automation and Integration: The Python script bridges Terraform’s provisioning phase with Ansible’s configuration phase.
- Modularity: The separation of Terraform and Ansible components highlights a modular approach, allowing each stage (provisioning and configuration) to be independently managed and maintained.

##### Relevant Technologies, Frameworks, or Libraries
- Terraform: For provisioning DigitalOcean infrastructure.
- Ansible: For configuring and managing the server environment.
- Python: For automating Terraform operations and updating the Ansible inventory dynamically.
- DigitalOcean API: The cloud provider’s API is a key external interaction point.
- Nginx and MySQL: As part of the web server configuration, represented in the Ansible playbook and nginx.conf.j2 template.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer/CI Environment
    subgraph "Developer/CI Environment"
        A["manage_terraform.py"]:::python
    end

    %% Infrastructure Provisioning Layer
    subgraph "Infrastructure Provisioning"
        B["Terraform Configuration"]:::terraform
        B1["main.tf"]:::terraform
        B2["provider.tf"]:::terraform
        B3["variables.tf"]:::terraform
        B4["outputs.tf"]:::terraform
        B5["terraform.tfvars.example.md"]:::terraform
        C["DigitalOcean API"]:::external
        %% Connect Terraform Configuration to its files
        B --> B1
        B --> B2
        B --> B3
        B --> B4
        B --> B5
    end

    %% Configuration Management Layer
    subgraph "Configuration Management"
        D["Ansible Inventory"]:::ansible
        E["Ansible Configuration"]:::ansible
        E1["setup.yml"]:::ansible
        E2["ansible_vars_example.yml"]:::ansible
        F["Nginx Configuration Template"]:::ansible
        %% Connect Ansible Configuration to its files
        E --> E1
        E --> E2
    end

    %% Provisioned Droplet
    G["DigitalOcean Droplet (Nginx & MySQL)"]:::droplet

    %% Data Flow
    A -->|"triggers"| B
    B -->|"provisions"| C
    C -->|"creates"| G
    A -->|"updates"| D
    D -->|"used_by"| E
    E -->|"configures"| G
    A -->|"orchestrates"| E

    %% Click Events
    click B1 "https://github.com/abednahouli/terraform_seed/blob/master/main.tf"
    click B2 "https://github.com/abednahouli/terraform_seed/blob/master/provider.tf"
    click B3 "https://github.com/abednahouli/terraform_seed/blob/master/variables.tf"
    click B4 "https://github.com/abednahouli/terraform_seed/blob/master/outputs.tf"
    click B5 "https://github.com/abednahouli/terraform_seed/blob/master/terraform.tfvars.example.md"
    click A "https://github.com/abednahouli/terraform_seed/blob/master/manage_terraform.py"
    click E1 "https://github.com/abednahouli/terraform_seed/blob/master/setup.yml"
    click E2 "https://github.com/abednahouli/terraform_seed/blob/master/ansible_vars_example.yml"
    click F "https://github.com/abednahouli/terraform_seed/blob/master/nginx.conf.j2"

    %% Styles
    classDef terraform fill:#fdd,stroke:#900,stroke-width:2px;
    classDef python fill:#ddf,stroke:#00f,stroke-width:2px;
    classDef ansible fill:#dfd,stroke:#090,stroke-width:2px;
    classDef external fill:#ffd,stroke:#990,stroke-width:2px;
    classDef droplet fill:#fc9,stroke:#c60,stroke-width:2px;

    class A python;
    class B,B1,B2,B3,B4,B5 terraform;
    class C external;
    class D,E,E1,E2,F ansible;
    class G droplet;
```
