.sh: The poor man's Infrastructure-as-Code

Infrastructure as Code (IaC) is all the rage. And for good reason. It can simplify many common tasks.

But first, for the uninitiated, what is it?

In a nutshell, it’s the process of managing computers (servers, VMs, even entire data centers) via code, as opposed to the “old way”: manual configuration.

This has the potential to provide a number of clear benefits. Two I’ll highlight:

  1. Scaling Perhaps most obvious, it helps with scaling. If you need to install 1,000 servers, doing it manually would take weeks or longer. If you can do it with some code, then at least the human interaction probably takes just a few minutes, then you can walk away to play Fallout or something, while the servers chug away in the background.

  2. Reproducibility Even with a small number of servers (like, I don’t know… one?) there can be a benefit in reproducibility. Think back to the last time you got a new laptop and you had to configure everything just the way you like it. You probably installed your favorite browser. Your favorite music player. Your favorite text editor. Then you had to enable dark mode. Oh, and you had to configure your mail client again… If you had all of this configuration as code, then in principle you could just run your code, and have a working environment.

The same is nice for servers. Most companies have multiple environments. Production, staging, and dev are common. Some companies have many more. In principle, these should be as close to identical as possible (otherwise your testing may not validate that your application will work in production).

There are many tools to tackle this problem, at different layers of the technology stack.

But you don’t need to learn any new tools to start taking advantage of IaC.

I’m helping a small startup right now configure their production and staging environments on Google Cloud. And the main tool I’m using to ensure that these two environments are identical is a simple bash script.

The script is little more than a list of commands necessary to provision and configure one of their environments. It executes the necessary gcloud, kubectl and helm commands to create a Cloud SQL database, set up some networking, and launch the necessary services.

IaC can be very complex. But it doesn’t need to be. Start small. Start with the tools you know today.

If you enjoyed this message, subscribe to The Daily Commit to get future messages to your inbox.