# hashicorp-education/learn-packer-hcp-golden-image architecture

> Architecture diagram of the GitHub repository hashicorp-education/learn-packer-hcp-golden-image, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hashicorp-education/learn-packer-hcp-golden-image
- Repository: https://github.com/hashicorp-education/learn-packer-hcp-golden-image

## Overview

##### Main pieces
- Golden Image Build Pipeline: Highlight the primary “golden-image” directory. This is where the main configuration (like audit rules, bootstrap scripts, and Packer configuration files) sets up the base or “golden” image.
- Application-Specific Images: Notice the directories “hashicups-image” and “loki-image.” These represent specialized images—one for a sample (likely a demo application) and another for monitoring/logging (given the inclusion of a Loki config).
- Infrastructure Provisioning: The “infrastructure” directory contains Terraform configurations (main.tf, outputs.tf, variables.tf, etc.). This section is responsible for setting up the underlying cloud or network resources (such as VPCs, security groups) needed for deployment.
- Notification and Automation: The “notif-webhook” directory holds configurations and a Python-based Lambda function (lambda.py) along with its Terraform files. This component likely manages notifications or triggers in response to pipeline events.

##### Their interactions
- The Packer configurations (with the .pkr.hcl files in each image directory) serve as the pipeline’s building blocks that transform source configurations into deployable golden images.
- The Infrastructure component (Terraform scripts) provisions all necessary resources in the cloud, which are required for running or deploying these images.
- The Notification system (Lambda via notif-webhook) listens to events (for example, build completions or failures) and potentially sends alerts to external systems.
- There’s a clear vertical integration where the image build (using HCP Packer) ties into both the provisioning (Terraform) and the operational monitoring/notification components.

##### Architectural patterns and design principles
- Separation of Concerns: The project splits responsibilities into different directories – one for image building (with further specialization into base, application, and monitoring images), one for infrastructure provisioning, and one for notification mechanisms.
- Infrastructure as Code (IaC): The use of Terraform scripts indicates that the infrastructure is managed in a declarative, version-controlled manner.
- Pipeline Modularity: Each image (golden, hashicups, loki) has its own set of scripts and configuration files, suggesting that these components can evolve independently or be replaced based on different use cases.
- Automation & Integration: With scripts to bootstrap and set up components (e.g., run-promtail.sh, start-hashicups.sh) along with a webhook notification through Lambda, the pipeline emphasizes automated integration and deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Golden Image Pipeline (HCP Packer)"
        A["Golden Image (Base)"]:::image
        B["Hashicups Image (Application)"]:::image
        C["Loki Image (Monitoring)"]:::image
    end

    D["Infrastructure Provisioning (Terraform)"]:::infra
    E["Notification/Automation (Lambda Webhook)"]:::notif

    %% Deployment flow: Images are built then deployed
    A -->|"deploys"| D
    B -->|"deploys"| D
    C -->|"deploys"| D

    %% Notification flow: Build events and infrastructure events trigger notifications
    D -->|"alerts"| E
    A -->|"notifies"| E
    B -->|"notifies"| E
    C -->|"notifies"| E

    %% Click Events
    click A "https://github.com/hashicorp-education/learn-packer-hcp-golden-image/tree/main/golden-image/"
    click B "https://github.com/hashicorp-education/learn-packer-hcp-golden-image/tree/main/hashicups-image/"
    click C "https://github.com/hashicorp-education/learn-packer-hcp-golden-image/tree/main/loki-image/"
    click D "https://github.com/hashicorp-education/learn-packer-hcp-golden-image/tree/main/infrastructure/"
    click E "https://github.com/hashicorp-education/learn-packer-hcp-golden-image/tree/main/notif-webhook/"

    %% Styles
    classDef image fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef infra fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef notif fill:#ffa500,stroke:#000,stroke-width:2px;
```
