Infrastructure As Code: An Ultimate Guide

Infrastructure-as-code is a fundamental skill for cloud native software engineers for working with cloud applications. Writing infrastructure-as-code helps software engineers to document their infrastructure, iterate on it faster, apply code review process to it, etc.

By the end of this article you should understand what infrastructure-as-code is, the benefits, and the main tools that you should know when it comes to infrastructure-as-code. 

What is infrastructure-as-code?

Infrastructure as code is the practice of keeping all of your infrastructure code within version control. Infrastructure-as-code can be done using a tool such as Terraform, Chef, Puppet or Ansible. In order to qualify as infrastructure-as-code all you need to do is write it in code format, and share it using some form of version control system.

For a more in-depth explanation, read the full article on Infrastructure as Code: A quick and simple explanation.

What are the main Benefits of Infrastructure As Code?

Okay, so what are the main benefits of infrastructure-as-code?

Collaboration — When Infrastructure is written as code, different team members are able to collaborate on the software in the same way they would with regular application code.

Disaster recovery — If your infrastructure is destroyed for whatever reason, having it written as code enables you to re-launch your infrastructure by running a few simple commands.

Documentation — When infrastructure isn’t written as code it becomes scary to touch and modify. Infrastructure written as code allows new developers to contribute to software safely.

Refactoring — Infrastructure that is written as code can be easily refactored, moved around and manipulated. Read about how 3 Terraform features help you to write malleable infrastructure as code.

Declarative vs Imperative Infrastructure As Code

Not all infrastructure-as-code is born the same. We have two flavours: Declarative and imperative. Declarative infrastructure as code declares the end state that you want your infrastructure as code to achieve. Then, your infrastructure as code tool will work out what changes are required in order to get there. Whereas imperative infrastructure-as-code is a step by step instruction on how to create infrastructure.

Declarative infrastructure-as-code typically comes with the ability to operate on the full life-cycle create, update, delete etc. Whereas imperative typically only works on the ones that have been coded for, so just creating, or updating, or deleting.

For a more in-depth explanation, read the full article on Declarative vs. Imperative Infrastructure As Code

What are the main Infrastructure As Code tools?

  • TerraformTerraform is a tool created by Hashicorp. It’s independent of other cloud providers and is mostly used for resource provisioning.
  • CloudFormationCloudFormation is the implementation of infrastructure-as-code in AWS.
  • Puppet / ChefPuppet and Chef are configuration management tools that help you to script your configuration changes.
  • AnsibleAnsible is a stand-alone infrastructure as code tool. Engineers use Ansible to run remote commands on servers via SSH.

Get started with Infrastructure As Code?

If you’re wanting to start learning cloud tools, the first step that I’d recommend is taking a look at infrastructure-as-code. Why? To get the long answer, read 5 Important Reasons To Learn Terraform Before Cloud Computing. But the short answer is: It has fast feedback loops,  it’s easy to rollback and you’re less likely to mess up on cloud costs.

So if you’re looking to get started with Infrastructure as code, the first tool I’d recommend you’d learn is Terraform. First up I’d suggest reading the article: Learn The 6 Fundamentals Of Terraform — In Less Than 20 Minutes. And then I’d suggest setting up an AWS account so that you can experiment. I wrote a free guide that you can get when you sign up to the newsletter which walks you through, step-by-step how to bootstrap your AWS account to get up and running with infrastructure-as-code.

Dive in!

Here is every article that I’ve written about Infrastructure As Code: