Why you need it

Someone sets up a server by hand, click by click, and it works. Months later it dies, and nobody remembers how much memory it had, which disk, or which boxes were ticked. Rebuilding it becomes guesswork, done in a hurry while the site is down.

Think of it like this

A recipe card instead of a cook's memory. If the cook leaves, anyone can follow the card and make the same cake again. Change the card, and every cake after it changes too.

Where you’ll find it

  • HashiCorp: Terraform reads files that describe servers, networks and databases, and creates them on almost any cloud.
  • AWS: CloudFormation builds a whole set of AWS resources from one template file.
  • Pulumi: Pulumi does the same job, but the settings are written in ordinary languages like Python or TypeScript.

What to know first

Server settings. Everything that makes a server what it is: memory, disk size, which programs are installed, which ports are open.

The code in main. The main shared copy of a team's code, kept with its full history, so every change has a date and a name on it.

How it works

  1. Write the settings down. Instead of clicking in a cloud console, you write each setting as a line in a file, like memory: 4 GB and disk: 50 GB. These are the rows in main in the animation.
  2. Keep the file with the code. The file lives in main next to the app. A change is reviewed like any other change, and you can see who changed what, and when.
  3. A tool builds from the file. A tool reads the file and asks the cloud for exactly that server. You describe what you want; the tool works out the clicks. This is the new server filling up line by line in the animation.
  4. Rebuild any time. When the server dies, run the same file again and you get the same server. Press "break the server" in the animation and watch the same rows build it again.

An example

A server was set up by hand two years ago. It dies on a Friday night.

By hand: an engineer spends 3 hours guessing settings, and gets the disk size wrong, so it fills up on Monday.

As code: the file says memory: 4 GB and disk: 50 GB. One command, about 5 minutes, and the new server matches the old one exactly.

Further reading

  • InfrastructureAsCode, Martin Fowler, on martinfowler.com. A short page on the idea and the habits that come with it. Start with this one.
  • SnowflakeServer, Martin Fowler, on martinfowler.com. What goes wrong with a server set up by hand that nobody can rebuild.
  • What is Terraform?, Terraform docs. How one popular tool turns files into real servers, step by step.