July 23, 2017 · AWS Terraform Infrastructure as Code DevOps

Infrastructure as Code using Terraform

One of the strategic benefits of Cloud-computing is the concept of programmable infrastructure or "Infrastructure as Code". So what exactly does this mean?

Historically, infrastructure provisioning has been done via a combination of shell scripts and manual operations. Of course, once a computing environment is initially built, it's often tweaked and modified over months to address various issues. This could leave the environment in an unknown state. Tracking it's state -- "What was changed? Why? by Whom?" is very involved. Rebuilding or cloning an entire environment could take days, if not weeks.

"Infrastructure as Code" provides a solution to this problem. It piggybacks on the API exposed by cloud providers like AWS and Azure and provides the ability to provision an entire computing environment, both application code AND the underlying infrastructure it runs on -- the networks, servers, load-balancers -- in a repeatable and versioned manner.

It's important to note that this code can be stored in a version control system and reviewed like application code. We can know the history of all the changes made. And the results of the code -- the current state of the infrastructure -- can also be saved and reviewed whenever needed.

One such tool to make this possible is Terraform from Hashicorp -- the company behind Vagrant, Consul and Vault.

To get a feel for Terraform as a tool, I've put together a small auto-scaling microservice project on Amazon Web Services. Hopefully this project will be simple enough to introduce some interesting concepts and challenging enough to help you get your hands dirty!

Note: The really interesting part of this project is that the microservice will be deployed to infrastructure that dynamically resizes itself (i.e "auto-scales") when load increases.

If this interests you, follow along. You will need an Amazon Web Services account to run this project but it should fall under the AWS free tier, which is always nice.

About Terraform:
Project Outline:

Before running the project:

1) Configure your local machine to interact with AWS:

2) If you don't already have a SSH keypair, you will need to generate one to login to your EC2 instances.

Okay, let's get to it!

Overview diagram:

Inputs:
Script outline:
Terraform demo:
Exercises for the reader:
Summary:

Managing computing environments using the "infrastructure as code" approach is rapidly becoming a de-facto standard. It's one of the core concepts to grasp in order to build agile, elastic, cloud-native software systems of the future. Hope you find this project helpful in your learning journey!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket