By Hemanta Sundaray on 2023-02-14
When studying infrastructure as code tools such as Ansible, Chef, Puppet, and Terraform, you'll come across two key concepts: "mutable" and "immutable" infrastructure. If you are new to infrastructure automation, these terms can be a bit difficult to wrap your head around.
Don't worry, though. In this blog post, I'll break down these concepts in a simple, straightforward way. Let’s get started!
Let's say you have a web server running with an older version of NGINX and you want to update it to the newer version. To do this under an immutable approach, you would follow these steps:
It's important to note that the immutable approach provides a more consistent and predictable environment. This makes it easier to roll back and recover from errors. Also, the new image can be used as a base image for future instances and can save you the time of installing and configuring the software on new servers.
Under a mutable approach, you would update the existing servers in place. You wouldn’t have to create a new server image or replace the existing servers. Here are the steps you would take to update the NGINX servers under a mutable approach:
It's important to note that this approach allows for more flexibility and the ability to roll back changes if necessary.
Here's an analogy that can help you understand the distinction between mutable and immutable infrastructure more clearly.
Imagine you have a house and you want to change the front door. With the immutable approach, it's like building a brand new house just for the sake of changing the front door. You'd construct the new house with the new door already installed, test it out to make sure it's working properly, and then move in. The old house (with the old door) gets demolished and you're left with only the new house (with the new door). It's a bit like starting from scratch, but it ensures that everything is consistent and predictable.
With the mutable approach, it's like just changing the front door on the existing house. You'd remove the old door, install the new door, test it out to make sure it's working properly, and then call it a day. The rest of the house stays the same, and you're able to keep any of the previous configurations. It's a bit more flexible and allows you to roll back changes if necessary.