How hashicorp-education/learn-packer-hcp-golden-image works
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.