# r3dact3d/aap-2.5-containerized-on-aws architecture

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

- Interactive diagram: https://gitdiagram.com/r3dact3d/aap-2.5-containerized-on-aws
- Repository: https://github.com/r3dact3d/aap-2.5-containerized-on-aws

## Overview

##### Main Components
- GitHub Repository: Represent the codebase which includes the Terraform configuration, GitHub Actions workflows (in .github/workflows), and post_data assets (e.g., the AAP installer package and manifest files).
- GitHub Actions Workflow: Show the pipeline that reacts to pull requests and push events. Include steps like checking out the code, setting up AWS credentials, running Terraform commands (init, validate, plan, and apply), and verifying S3 bucket existence.
- Terraform Infrastructure: Illustrate the components described in the Terraform files (main.tf, output.tf, user_data.txt). This component provisions:
- AWS EC2 Instance (a RHEL 9 machine) to run the Ansible Automation Platform.
- AWS S3 Bucket for state storage (as indicated by the environment variables used in the workflow).
- EC2 Instance Configuration & Provisioning: Detail how the provisioner “remote-exec” in main.tf configures the instance, including:
- Installing necessary packages (Ansible, wget, git, etc.).
- Setting the hostname.
- Downloading and extracting the AAP container bundle from post_data.
- Configuring SSH keys and the Ansible inventory.
- External Services & Credentials: Note the integration with AWS (for instance provisioning, S3, and credentials), and the Red Hat subscription services (using secrets like ORG_ID, ACTIVATION_KEY, RHN_USER, RHN_PASS).

##### Relationships and Data Flow
- That code changes in the GitHub repository (especially in the terraform directory) trigger the GitHub Actions workflows.
- That the EC2 instance (once created) runs scripts via remote_exec which download and run Ansible installation scripts from files in the post_data directory.
- How outputs from Terraform (like the public IP of the instance) feed back to allow SSH access for manual validation and post-infrastructure checks.

##### Architectural Patterns and Design Principles
- Infrastructure-as-Code (IaC): The use of Terraform for reproducible, automated infrastructure provisioning.
- CI/CD: The GitHub Actions workflow automates planning and applying changes based on branch events (pull_request for planning, push for apply).
- External Configuration and Secrets Management: Integration with AWS Secrets and external systems like Red Hat subscriptions highlight secure and parameterized deployment.

##### Final Touches
- Summaries or callouts for conditional logic used in the GitHub Actions workflow to differentiate between pull_request and push events.
- Relevant annotations about the use of external services (AWS, Red Hat) and dependencies like the post_data resources that are crucial for the Ansible installation.

This detailed decomposition will allow any observer (including a principal software engineer) to understand the overall system, the critical integration points, and the steps taken from code commit to a running Ansible Automation Platform instance on AWS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Source Control & CI/CD"
        GHRepo["GitHub Repository"]:::repo
        GHActions["GitHub Actions Workflow"]:::pipeline
    end

    subgraph "Infrastructure Provisioning"
        TerraformInfra["Terraform Infrastructure"]:::infra
        EC2Config["EC2 Instance Config"]:::config
        UserData["User Data Script"]:::config
    end

    subgraph "AWS Resources"
        EC2["AWS EC2 Instance (RHEL 9)"]:::aws
        S3["AWS S3 Bucket (State Storage)"]:::aws
        PostData["Post-Data Assets for AAP Installation"]:::assets
    end

    %% Connections
    GHRepo -->|"triggers"| GHActions
    GHActions -->|"executes"| TerraformInfra
    TerraformInfra -->|"provisions"| EC2
    TerraformInfra -->|"provisions"| S3
    EC2Config -->|"configures"| EC2
    UserData -->|"appliedTo"| EC2
    EC2 -->|"downloads"| PostData

    %% Click Events
    click GHRepo "https://github.com/r3dact3d/aap-2.5-containerized-on-aws/tree/ansible/(Entire repository structure)"
    click GHActions "https://github.com/r3dact3d/aap-2.5-containerized-on-aws/tree/ansible/.github/workflows"
    click TerraformInfra "https://github.com/r3dact3d/aap-2.5-containerized-on-aws/tree/ansible/terraform"
    click EC2Config "https://github.com/r3dact3d/aap-2.5-containerized-on-aws/blob/ansible/terraform/main.tf"
    click UserData "https://github.com/r3dact3d/aap-2.5-containerized-on-aws/blob/ansible/terraform/user_data.txt"
    click PostData "https://github.com/r3dact3d/aap-2.5-containerized-on-aws/tree/ansible/post_data"

    %% Styles
    classDef repo fill:#f0f8ff,stroke:#000,stroke-width:2px;
    classDef pipeline fill:#d1e7dd,stroke:#000,stroke-width:2px;
    classDef infra fill:#fff3cd,stroke:#000,stroke-width:2px;
    classDef config fill:#cfe2ff,stroke:#000,stroke-width:2px;
    classDef aws fill:#f8d7da,stroke:#000,stroke-width:2px;
    classDef assets fill:#d1e7dd,stroke:#000,stroke-width:2px;
```
