How plus3it/terraform-aws-org-new-account-delete-default-vpcs works
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.