# plus3it/terraform-aws-org-new-account-delete-default-vpcs architecture

> Architecture diagram of the GitHub repository plus3it/terraform-aws-org-new-account-delete-default-vpcs, 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/plus3it/terraform-aws-org-new-account-delete-default-vpcs
- Repository: https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs

## Overview

##### Overall Project Type and Purpose
- This project is a Terraform module designed to automatically delete default VPCs across every AWS region for any new or invited AWS accounts in an AWS Organization.
- Its core functionality is driven by an AWS Lambda function (written in Python) that is triggered by specific AWS Organization events (such as CreateAccountResult and InviteAccountToOrganization) through an EventBridge rule.
- The project also provides a CLI for manual triggering and testing, and it includes CI/CD configuration files to support quality checks and automated releases.

##### File Structure
- The directory “src” contains the Python source code for the deletion logic (delete_default_vpc.py) – that is the core Lambda function logic.
- The “scripts” directory contains an additional piece (create_default_vpc) used to create or perhaps manage default VPCs, indicating support scripts are available as well.
- The “tests” directory shows testing infrastructure (with a main.tf configuration) aimed at validating the module's behavior.
- CI/CD configuration in the “.github” directory (workflows for linting, testing, and releases) highlight the operational aspects ensuring code quality.

##### Key Architectural Components and Interactions
- Terraform Module: Acts as the infrastructure-as-code layer deployed into AWS. This includes resources defined in main.tf, variables.tf, and versions.tf.
- AWS Lambda Function: Implemented in src/delete_default_vpc.py, this is the main component that:
- Is triggered by AWS Organization events.
- Iterates through all AWS regions.
- Deletes any resources related to the default VPC.
- Utilizes multi-threading (controlled by a configurable MAX_WORKERS parameter) to handle deletions concurrently.
- Event Triggers and AWS EventBridge: AWS CloudWatch/EventBridge rules are used to capture events like “CreateAccountResult”, “InviteAccountToOrganization”, and “EnableOptInRegion”, and trigger the Lambda.
- IAM Roles and Policies: The module provisions or expects an IAM role (typically “OrganizationAccountAccessRole” or a custom role) which is assumed by the Lambda in the target account for executing deletion actions.
- CI/CD Pipeline: GitHub workflows (lint, release, test) automate testing, building, and deployment of the infrastructure and code, ensuring that the module remains robust.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Operational Processes
    subgraph "Operational Processes"
        cicd["CI/CD Pipeline"]:::cicd
        test["Testing Infrastructure"]:::testing
    end

    %% Infrastructure as Code
    subgraph "Infrastructure as Code"
        subgraph "Terraform Module"
            tf1["main.tf"]:::terraform
            tf2["variables.tf"]:::terraform
            tf3["versions.tf"]:::terraform
        end
        ts["Supplementary Script"]:::script
    end

    %% AWS Cloud Components
    subgraph "AWS Cloud"
        eb["EventBridge Trigger"]:::awsService
        lamb["Lambda - Delete Default VPC"]:::lambda
        iam["IAM Roles & Policies"]:::iam
        api["AWS API Calls (VPC Deletion)"]:::awsService
    end

    %% Relationships from Operational Processes to Infrastructure
    cicd -->|"deploys"| tf1
    test -->|"validates"| tf1

    %% Terraform Module provisions AWS resources
    tf1 -->|"provisions"| eb
    tf1 -->|"provisions"| lamb
    tf1 -->|"provisions"| iam

    %% AWS Cloud interactions
    eb -->|"triggers"| lamb
    lamb -->|"calls"| api
    lamb -->|"assumes"| iam

    %% Manual trigger via Supplementary Script
    ts -->|"manual_trigger"| lamb

    %% Click Events for Component Mappings
    click tf1 "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/blob/main/main.tf"
    click tf2 "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/blob/main/variables.tf"
    click tf3 "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/blob/main/versions.tf"
    click lamb "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/blob/main/src/delete_default_vpc.py"
    click ts "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/tree/main/scripts/create_default_vpc/"
    click cicd "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/tree/main/.github/workflows/"
    click test "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/blob/main/tests/test_delete_default_vpc/main.tf"
    click cicd "https://github.com/plus3it/terraform-aws-org-new-account-delete-default-vpcs/blob/main/.github/dependabot.yml"

    %% Styling Classes
    classDef terraform fill:#FFEB3B,stroke:#333,stroke-width:2px;
    classDef awsService fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef lambda fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef iam fill:#FFE0B2,stroke:#E65100,stroke-width:2px;
    classDef cicd fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef testing fill:#F8BBD0,stroke:#AD1457,stroke-width:2px;
    classDef script fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
```
