Managing IT infrastructure is a hard job, but in recent years cloud providers have been making it easier to automate every aspect of a sysadmin’s life. Infrastructure as Code is the next step: defining all of your services in a configuration file which can be tracked through source control.

How Does Infrastructure as Code Work?

Infrastructure as Code (IaC) is pretty simple in theory. All of your server deployments, cloud services, and their associated configuration are all stored in one centrally modifiable configuration file or set of configuration files, usually YAML or something similar. Each configuration file contains the necessary instructions and directives to recreate your entire cloud solution from scratch.

This core principle means that modifications to this infrastructure can be tracked with source control. Want to launch a new server? You’ll need to modify your deployment config and push an update. If something goes wrong, you can always revert to an earlier version of your deployment, which can be very useful for high availability systems where a misconfigured deployment can cost a lot of money.

This means IaC is very all-or-nothing. It’s not a good idea to run IaC alongside manually managed deployments, though you certainly can do so, especially if the systems are separate.

In practice, infrastructure as code is quite complicated. If you thought regular sysadmining was a difficult job, converting your entire deployment to IaC will not be a simple task. But, once you’ve done the hard part of setting it up, maintaining your deployment and making changes becomes much easier. No longer will all of your deployment settings live in your sysadmin’s head—with IaC, it’s all clearly defined in code.

And, since it’s all defined in code, you can also easily automate the process of running development, staging, testing, and production environments. This way, you can test changes to your entire deployment before updating. You could even automate IaC unit tests if you desired.

While it’s quite complicated to set up, the benefits for larger projects certainly outweigh the potential headaches.

Using Infrastructure as Code

Naturally, codifying your entire infrastructure can be an arduous process. You don’t always have to create the YAML template manually though; AWS’s CloudFormation IaC solution features a web based “Designer,” which will display your whole product stack visually. For example, here is one of the sample templates, for an autoscaling, load balanced WordPress deployment using an RDS instance as the database.

cloudformation wordpress instance

Each individual node requires configuring, but in the end, it will produce a template file that you can use to create the whole deployment from.

cloudformation sample template

The exact implementation will vary depending on provider, but AWS CloudFormation will handle creating all resources in the proper order. For example, if you have an EC2 instance with a security group, CloudFormation will make sure to create the security group first, and then create the instance with that security group. All you have to do is link them together in the console.

For more information on CloudFormation, you can read our guide to getting started with it.

RELATED: Codify Your AWS Infrastructure With CloudFormation

Profile Photo for Anthony Heddings Anthony Heddings
Anthony Heddings is the resident cloud engineer for LifeSavvy Media, a technical writer, programmer, and an expert at Amazon's AWS platform. He's written hundreds of articles for How-To Geek and CloudSavvy IT that have been read millions of times.
Read Full Bio »