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

Preface

As a frequent blogger of HashiCorp products, it’s an honor to present this more thorough exploration of the open source Packer tool. Packer is one of HashiCorp’s simplest and most elegant tools with one simple task. It builds images and artifacts in a consistent way for different environments and cloud projects. If you’re thinking of carrying out a lift-and-shift migration, there are a series of questions you may have:

  • What operating system will you boot with?
  • How will you apply updates and test patches across your development lifecycle?
  • How can you ensure your on-premises images match the ones in your global cloud environments?
  • What if you have multiple clouds to keep track of?
  • How can you build matching container images for serverless environments or orchestration platforms?

These are the questions that Packer solves for most users. On the journey of writing this book, I went even deeper to try and show how Packer can do even more than it was built for. I wanted to answer the questions that people don’t think to ask about Packer. In addition to cloud environments, we’ll explore everything from the high-level basics of local environments to complex cloud image libraries. We’ll even push Packer further and experiment with some interesting use cases Packer hasn’t necessarily been positioned for. The questions you’ll be asking afterward may surprise you:

  • Are your cloud applications prepared for ARM or RISC-V architectures to cut your compute costs in half?
  • Can you run tests and compliance profiles as part of your automation pipelines?
  • Can you build and test mobile apps along with your cloud images?
  • Can you build and test your IoT devices and microcontrollers along with a cloud backend?
  • Can Packer save you time on slow Terraform tasks?

The answers to these questions are surprising, and it turns out Packer can do every one of these things. It can replicate your local VMware environments in the cloud for lift-and-shift workloads. It can update your container image registry at the same time as it builds a virtual image or even a bare-metal environment for storage or network booting. This book and the corresponding GitHub repo show you how.

This book starts off with a foundation of manual builds, working our way up to build automation. Build automation can help speed up your development experience, so you may want to go back over the book in reverse using automation.

I would like to thank a few members of the Packer engineering team who have occasionally tested, provided feedback, or helped guide some of the sample code for this book, namely Megan Marsh, Wilken Rivera, and Lucas Bajolet.

Any author commissions for this title will be donated to the Raspberry Pi Foundation to encourage kids to learn how to code.