ChrisAdkin8 / Packer-Golden-Image-Pipeline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

This repo illustrates how to create a golden image pipeline using Packer and Terraform, specifically, how to build an virtual machine image using Packer, store the metadata for it in a HCP Packer registry and then finally create a virtual machine using an image referenced from the registry:

The Packer element of the workflow largely mirrors the contents of this HashiCorp tutorial, the rest of the repo provides additional context and links the Packer element to Terraform.

The pipeline comprises of the following stages:

  1. Packer HCL file creation for golden images, these are essentially text files which specify how to create images in Packer's dialect of HashiCorp Configuration Language (HCL).

  2. Building an image via Packer and pushing its metadata to HCP Packer.

  3. As part of the packer build process, the image metadata is pushed to a HCP Packer registry.

  4. Create a Terraform configuration that references the image in the HCP Packer registry via the hcp-packer-terraform data source.

Prerequisites

Generic Prerequisites

AWS Prerequisites

  • An AWS account with credentials set as local environment variables. These credentials must have permissions to create, modify, and delete EC2 instances. Refer to the documentation to find the full list IAM permissions required to run the amazon-ebs builder.

Azure Prerequisites

  • An Azure account
  • Azure CLI installed locally

Instructions

  1. Build and push images to a HCP Packer registry by following the instructions here

  2. Once an image has been successfully pushed up to the HCP Packer registry, virtual machines can be created using these images per these instructions.

Terraform Cloud / Enterprise HCP Packer Run Task Integration

Terraform Cloud and Terraform Enterprise add further value to this solution via run task integration - this validates that the machine images in your Terraform configuration are not revoked for being insecure or outdated. Refer to this tutorial for further information on this subject.

About

License:Apache License 2.0


Languages

Language:HCL 100.0%