HashiCorp Packer

HashiCorp Packer Basics

Mutable Infrastructure

In this lesson, we’ll explore how HashiCorp Packer integrates into application deployment by comparing mutable and immutable infrastructure paradigms. Understanding mutable infrastructure is the first step toward seeing the advantages Packer brings.

What Is Mutable Infrastructure?

Mutable infrastructure refers to servers (physical or virtual) that are continuously updated and modified after initial provisioning. A typical workflow looks like this:

  1. Develop your application code.
  2. Provision a server instance.
  3. Install the operating system (e.g., CentOS, Fedora, Ubuntu).
  4. Install packages and dependencies.
  5. Harden and secure the server (firewall rules, user permissions).
  6. Deploy and start your application.
  7. Maintain with ongoing patches, upgrades, and configuration tweaks.

Each in-place change mutates the system state, and over time, these mutations can lead to inconsistencies across servers.

while (alive) {
  eat();
  sleep();
  code();
  repeat();
}

Challenges of Mutating Live Servers

Applying updates or security hotfixes directly on running servers may work at small scale but leads to:

  • Human error: Manual updates on many servers increase the risk of typos and missed steps.
  • Configuration drift: Minor differences accumulate, causing environments to diverge and making debugging harder.

Automation tools like Ansible mitigate some risks by orchestrating parallel updates. However, since servers still mutate in place, drift can persist.

The image illustrates a "Mutable Infrastructure" setup using Ansible, showing a central Ansible logo connected to multiple server and database icons.

Warning

Relying solely on mutable operations can lead to untracked changes and compliance issues due to hidden configuration drift.

Comparing Mutable vs Immutable Infrastructure

AspectMutable InfrastructureImmutable Infrastructure
Update processIn-place patches and upgradesReplace entire hosts or containers
ReproducibilityProne to configuration driftConsistent, versioned images
RecoveryRollbacks can be error-proneQuick rollback by redeploying a known-good image
Tooling examplesAnsible, Chef, PuppetHashiCorp Packer, Docker, Kubernetes, Terraform

Note

Immutable infrastructure patterns use tools like Packer to bake golden images, eliminating in-place mutations and ensuring consistency across environments.

References

Watch Video

Watch video content

Previous
What is Packer