# amanpathak-devops/eks-terraform-github-actions architecture

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

- Interactive diagram: https://gitdiagram.com/amanpathak-devops/eks-terraform-github-actions
- Repository: https://github.com/amanpathak-devops/eks-terraform-github-actions

## Overview

##### Project Type and Purpose
- This is an **Infrastructure-as-Code (IaC)** project that uses Terraform to provision AWS EKS clusters and GitHub Actions (plus an optional Jenkins pipeline) to automate plan/apply operations.
- The goal is to provision “production-ready” EKS clusters, complete with VPC, IAM roles, and supporting services, all orchestrated through GitHub workflows (and optionally Jenkins).

##### File Structure
Top-level components:
- .github/workflows/terraform.yml → GitHub Actions CI workflow
- Jenkinsfile → Jenkins pipeline alternative
- eks/ → Terraform code for a specific environment (dev)
– backend.tf (remote state config)
– main.tf (EKS cluster resource definitions)
– variables.tf + dev.tfvars
- module/ → reusable Terraform modules
– vpc.tf (VPC, subnets, routing)
– iam.tf (IAM roles, policies)
– eks.tf (EKS cluster, node groups)
– gather.tf (data sources or “gather” patterns)
– variables.tf
- assets/ → presentation GIF

##### README Insights
- Confirms use of Terraform + GitHub Actions for EKS provisioning.
- Mentions Infrastructure as Code and CI/CD automation.

##### Main Components & Relationships
a. **CI/CD Layer**
- Developers push Terraform code to GitHub
- GitHub Actions workflow triggers on push/PR
- (Optionally) Jenkins pipeline can run terraform plan/apply
b. **Terraform Orchestration**
- Runs `terraform init` against remote backend (S3 + DynamoDB)
- Executes `terraform plan` and `terraform apply`
- Loads modules from `module/` folder
c. **AWS Infrastructure**
- **VPC Module**: Creates VPC, subnets (public/private), route tables
- **IAM Module**: Defines IAM roles, policies for EKS + nodes
- **EKS Module**: Provisions EKS control plane, node groups
- **Gather Module**: Pulls in data sources (e.g., existing subnets, AMIs)
d. **State Management**
- Terraform backend (S3 bucket + DynamoDB) ensures state locking & versioning
e. **External Services**
- AWS EKS, S3, DynamoDB
- GitHub Actions
- (Optional) Jenkins + its agents

##### Architectural Patterns & Principles
- **Modular Terraform**: separation of concerns via modules (VPC, IAM, EKS)
- **Remote State Management**: backend.tf for state storage and locking
- **CI/CD as Code**: workflows declaratively defined in YAML
- **Environment Isolation**: dev.tfvars allows environment-specific overrides

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CI/CD Layer"
        Developer["Developer"]:::external
        GitHub["GitHub Actions Workflow"]:::cicd
        Jenkins["Jenkins Pipeline"]:::cicd
    end

    Developer -->|push code| GitHub
    GitHub -->|trigger workflow| TerraformCLI
    Jenkins -->|trigger pipeline| TerraformCLI

    TerraformCLI["Terraform CLI\n(init / plan / apply)"]:::module

    subgraph "Terraform Env (dev)"
        BackendTF["backend.tf"]:::module
        MainTF["main.tf"]:::module
        VarsTF["variables.tf"]:::module
        DevTF["dev.tfvars"]:::module
        LockFile[".terraform.lock.hcl"]:::module
    end

    TerraformCLI -->|init / apply| BackendTF
    TerraformCLI -->|provision| MainTF
    TerraformCLI -->|load vars| VarsTF
    TerraformCLI -->|override env| DevTF

    subgraph "Remote State Backend"
        S3["S3 Bucket"]:::state
        DynamoDB["DynamoDB Table"]:::state
    end

    TerraformCLI -->|terraform init| S3
    TerraformCLI -->|state lock| DynamoDB

    subgraph "Terraform Modules"
        VPCMod["VPC Module"]:::module
        IAMMod["IAM Module"]:::module
        EKSMod["EKS Module"]:::module
        GatherMod["Gather Module"]:::module
        ModuleVars["Module Variables"]:::module
    end

    TerraformCLI -->|load module| VPCMod
    TerraformCLI -->|load module| IAMMod
    TerraformCLI -->|load module| EKSMod
    TerraformCLI -->|load module| GatherMod
    TerraformCLI -->|load vars| ModuleVars

    subgraph "AWS Infrastructure"
        VPC["VPC & Subnets"]:::aws
        IAM["IAM Roles & Policies"]:::aws
        EKSCluster["EKS Control Plane"]:::aws
        NodeGroup["EC2 Node Groups"]:::aws
    end

    VPCMod --> VPC
    IAMMod --> IAM
    GatherMod --> VPC
    GatherMod --> IAM
    EKSMod --> EKSCluster
    EKSMod --> NodeGroup

    Doc["README.md"]:::external
    Assets["assets"]:::external

    Developer --> Doc
    Developer --> Assets

    %% Click Events
    click GitHub "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/.github/workflows/terraform.yml"
    click Jenkins "https://github.com/amanpathak-devops/eks-terraform-github-actions/tree/master/Jenkinsfile"
    click BackendTF "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/eks/backend.tf"
    click MainTF "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/eks/main.tf"
    click VarsTF "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/eks/variables.tf"
    click DevTF "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/eks/dev.tfvars"
    click LockFile "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/eks/.terraform.lock.hcl"
    click VPCMod "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/module/vpc.tf"
    click IAMMod "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/module/iam.tf"
    click EKSMod "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/module/eks.tf"
    click GatherMod "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/module/gather.tf"
    click ModuleVars "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/module/variables.tf"
    click Doc "https://github.com/amanpathak-devops/eks-terraform-github-actions/blob/master/README.md"
    click Assets "https://github.com/amanpathak-devops/eks-terraform-github-actions/tree/master/assets/Null"

    %% Styles
    classDef cicd fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef state fill:#90EE90,stroke:#000,stroke-width:1px
    classDef aws fill:#FFA500,stroke:#000,stroke-width:1px
    classDef module fill:#FFD700,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
