Book Image

HashiCorp Packer in Production

By : John Boero
Book Image

HashiCorp Packer in Production

By: John Boero

Overview of this book

Creating machine images can be time-consuming and error-prone when done manually. HashiCorp Packer enables you to automate this process by defining the configuration in a simple, declarative syntax. This configuration is then used to create machine images for multiple environments and cloud providers. The book begins by showing you how to create your first manifest while helping you understand the available components. You’ll then configure the most common built-in builder options for Packer and use runtime provisioners to reconfigure a source image for desired tasks. You’ll also learn how to control logging for troubleshooting errors in complex builds and explore monitoring options for multiple logs at once. As you advance, you’ll build on your initial manifest for a local application that’ll easily migrate to another builder or cloud. The chapters also help you get to grips with basic container image options in different formats while scaling large builds in production. Finally, you’ll develop a life cycle and retention policy for images, automate packer builds, and protect your production environment from nefarious plugins. By the end of this book, you’ll be equipped to smoothen collaboration and reduce the risk of errors by creating machine images consistently and automatically based on your defined configuration.
Table of Contents (18 chapters)
1
Part 1: Packer’s Beginnings
7
Part 2: Managing Large Environments
11
Part 3: Advanced Customized Packer

To get the most out of this book

It will help to have a basic understanding of the HashiCorp Configuration Language, known as HCL2. JSON is also offered as an alternate option to some HCL2 Packer uses. Packer and most HashiCorp projects are written in Golang, also known as Go, but this will only be necessary if encountering a bug in Packer or extending Packer by writing a plugin.

The Packer binary is built for most common platforms and architectures, including Linux and Windows, and the most common architectures, such as x86_64 and ARM/AArch64. Since Packer is statically linked, it relies on no external libraries and the underlying operating system shouldn’t affect the user experience unless using external plugins that aren’t built for your target platform.

Software/hardware covered in the book

Operating system requirements

HCL2

Platform agnostic

JSON

Platform agnostic

Golang

Platform agnostic

If running Packer in production, make sure to install only official releases signed with the HashiCorp engineering signing keys. The code for this book requires at least Packer version 1.7. Future releases may change behavior, so please verify the newest Packer release that works for you. For development or following along with this book, you may build Packer from the source or use a binary directly from the HashiCorp releases page: https://releases.hashicorp.com/packer/.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Every sample of code for this book can be considered platform agnostic. It can be run on Windows or Linux, or even Raspberry Pi. Adjust the code as necessary to suit your platform. Packer is designed to run on just about anything and remote builds in the cloud will not require large amounts of resources locally. Local builds or virtual machines may require local storage and RAM.