# claudio888/getip-infra-deploy-gaction architecture

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

- Interactive diagram: https://gitdiagram.com/claudio888/getip-infra-deploy-gaction
- Repository: https://github.com/claudio888/getip-infra-deploy-gaction

## Overview

##### Project Type and Purpose
- This is an “Infrastructure-as-Code” (IaC) repository for the getip-app, composed of Packer and Terraform configurations.
- It builds a custom AWS AMI (with Docker, Docker-Compose, AWS CLI, Python3) and then uses Terraform (with workspaces) to deploy Blue/Green environments (EC2, S3, Security Groups, local hosts file).

##### File Structure Highlights
- Top-level directories:
- .github/workflows: CI pipeline definition (ci.yml)
- packer: Packer image.json, setup.sh, and test script
- terraform: main.tf, modules (ec2, s3, security-group, localfile), vars, workspaces (dev-blue, dev-green), outputs.tf
- Key patterns: separation of image build (Packer) vs. infrastructure provisioning (Terraform), use of Terraform workspaces for immutable Blue/Green deployments.

##### README Insights
- Describes Packer custom image and Terraform resources.
- Explains Blue/Green deployment via Terraform workspaces (dev-blue vs. dev-green).
- Mentions Ansible role “get-hosts” in getip-app repo for dynamic hosts file in deployment (external to this repo).
- Lists AWS prerequisites (IAM keys, ECR, PEM key).

a. Main Components to Show
- Developer Workstation / CI (GitHub Actions)
- Packer Process (builds and pushes AMI to AWS)
- Terraform Process (plan/apply with workspace)
- AWS Cloud:
- EC2 Instances (blue group & green group) using the custom AMI
- S3 Bucket(s) for application logs or state (if used)
- Security Groups controlling ingress/egress
- Localfile resource producing hosts file for Ansible
- (Optional) Ansible Controller pointing at EC2 instances via generated hosts file

b. Relationships & Data Flows
- Flow from Terraform localfile → hosts file → Ansible (in getip-app)
- In AWS, show EC2 ↔ Security Group, EC2 ↔ S3 (if the app writes to S3)

c. Architectural Patterns & Design Principles
- Immutable Infrastructure: Packer-built AMI as golden image
- Blue/Green deployments via Terraform workspaces
- IaC modularity: separate modules/resources for EC2, S3, security groups, localfile
- CI/CD integration: GitHub Actions automates packer build & Terraform apply

d. Technologies & Frameworks
- Packer (image.json, setup.sh)
- Terraform (HCL, workspaces, modules)
- AWS (EC2, S3, IAM, Security Groups)
- Localfile provisioner
- (External) Ansible for application deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Prerequisites
    IAM["IAM Credentials"]:::external
    ECR["ECR Registry"]:::external
    PEM["PEM Key"]:::external

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI["GitHub Actions"]:::ci
    end

    %% Packer Phase
    subgraph "Packer Phase"
        Packer["Packer Builder"]:::build
    end

    %% AMI Registry
    AMI["AMI Registry"]:::runtime

    %% Terraform Phase
    subgraph "Terraform Phase"
        Terraform["Terraform Engine"]:::infra
    end

    %% AWS Cloud Resources
    subgraph "AWS Cloud"
        subgraph "Blue Environment"
            EC2B["EC2 (Blue)"]:::blue
        end
        subgraph "Green Environment"
            EC2G["EC2 (Green)"]:::green
        end
        S3["S3 Bucket"]:::runtime
        SG["Security Group"]:::runtime
        Hosts["Localfile Hosts File"]:::infra
    end

    %% Ansible Controller
    Ansible["Ansible Controller"]:::external

    %% Relationships
    IAM --> CI
    ECR --> CI
    PEM --> CI
    CI -->|"trigger packer build"| Packer
    Packer -->|"push AMI"| AMI
    CI -->|"trigger terraform"| Terraform
    AMI --> EC2B
    AMI --> EC2G
    Terraform --> EC2B
    Terraform --> EC2G
    Terraform --> S3
    Terraform --> SG
    Terraform --> Hosts
    Hosts -->|"generated hosts file"| Ansible

    %% Click Events
    click CI "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/.github/workflows/ci.yml"
    click Packer "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/packer/image.json"
    click Packer "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/packer/setup.sh"
    click Packer "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/packer/test_infra.py"
    click Terraform "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/main.tf"
    click Terraform "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/variables.tf"
    click Terraform "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/outputs.tf"
    click Terraform "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/terraform.gitignore"
    click EC2B "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/ec2.tf"
    click S3 "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/s3.tf"
    click SG "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/security-group.tf"
    click Hosts "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/localfile.tf"
    click Terraform "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/dev.tfvars"
    click Terraform "https://github.com/claudio888/getip-infra-deploy-gaction/blob/main/terraform/prod.tfvars"

    %% Styles
    classDef external fill:#E0F7FA,stroke:#006064;
    classDef ci fill:#F5F5F5,stroke:#424242;
    classDef build fill:#FFE0B2,stroke:#E65100;
    classDef infra fill:#FFF9C4,stroke:#F9A825;
    classDef runtime fill:#E1BEE7,stroke:#6A1B9A;
    classDef blue fill:#ADD8E6,stroke:#0000CD;
    classDef green fill:#90EE90,stroke:#008000;
```
