HomeOperationsAutomated OperationsHow simple Terraform plans make hybrid and multi-cloud a reality: an introduction

How simple Terraform plans make hybrid and multi-cloud a reality: an introduction

Most non-IT people will have heard about the word Terraform, will automatically think of this, changing dead planets into Earth like paradises.

When Teraform is not teraforming
Terraforming Mars will be an escapade in automation, just like terraforming your AWS environment.

But for those of us that work in Infrastructure and Cloud; Terraform is a language definition that allows the deployment of infrastructure as code. There is a loose analogy there, with Terraform you are building your environment exactly as you wish with a pre-configured script to create a predefined end point, just like the science fiction future environment building a new earth from barren rock.

Anybody who has utilized AWS will be aware of Terraform. It was written by Hashicorp and it is one of the primary methods used to automatically build AWS environments in this bold and new DevOps world.

What not a lot of people aware of is that Hashicorp’s Terraform can be utilized to build any infrastructure; all it requires is a provider. Currently Terraform is available for integration into all the major public cloud providers (AWS, Azure, GCP, Oracle Cloud and Alibaba Cloud). It is also available for on-prem environments with VMware and Microsoft Hyper-V.

In addition, Terraform supports all kinds of infrastructure platforms, like OpenStack and OpenShift. It also does containers with Docker and Kubernetes providers, and configures networking (for instance, Cisco’s ACI) and servers (Cisco’s UCS).

Terraform as a deployment methodology is truly cross-platform. This is in today’s hybrid and multi-cloud environment a truly powerful construct. But how simple is it to deploy into your environment and get started with deploying virtual machines into the cloud of your choice?

Terraform provides a relatively easy ride into usefulness for non-coders in Infrastructure teams. In fact, there is an easy-to-follow getting started on Hashicorp’s website. Reviewing this will give you a good grounding on the HCL (HashiCorp Configuration Language) language with specific focus on deploying infrastructure.

This is the first post into building a small environment on AWS, the rest of this post shows how to get started with Terraform to deploy a first automated virtual machine.

Deploying your first Terraformed Machine

Now let us dive into creating our first virtual machine using Terraform. To do so we must first install the correct binary for which ever system you are utilizing. A quick look at their download site shows that all major operating systems are supported: Mac, Linux, Windows, even Solaris and BSD. The file is download as zip file and in the case of a windows installation is as simple as double clicking the file, and adding the file to the path environment variable.

Let’s run a first command to get comfortable with the command line…

Terraform Version
How to find out your version

Pre-requisites for Terraform

Before we get started there are some pre-requisites to take care of:

  • a Python environment, coupled with pip3,
  • the AWS Terraform provider
  • a configuration file that describes the virtual machine we want to create.

First write your configuration file

provider "aws" {
access_key = "Your Access Key"
secret_key = "Your Secret Key"
region = "ap-southeast-2"
}

resource "aws_instance" "MyFirstTerraFormedVM" {
ami = "ami-da2ac3b8"
instance_type = "t2.micro"
}

Things to note are that you will need to create a user using the AWS IDM service to create and download your access and secret for it. Also you will need to make sure that the AMI identifier is correct for the region that you are deploying to.

Once the configuration file is complete, issue the following command:

 terraform init
Terraform Init
Initializing the Terraform Environment

We now have a working environment, so let’s create our first instance. It is considered good practice to issue the following command:

terraform plan
Terraform Plan
So, Will this work?

As we can see we are going to add a single machine this is evidenced by the line

Plan: 1 to add, 0 to change, 0 to destroy

Next lets deploy the machine into service, this is as simple as issuing the command:

terraform apply
Terraform Apply
Oh Look, my First Terraformed Instance.

So lets move over to AWS and verify the new machine:

AWS Verification
Oh Look it’s alive.

It’s been created as per spec by Terraform, without any manual interaction with the AWS console.

Summary

Well it is safe to say that this is a very simple deployment. This however, was more to show the simplicity of Terraform; we did not even scratch the surface of the power of the product.

The time from thinking about it to deploying a new virtual instance in a AWS VPC was less than an hour, and that included some one-time downloading and installing Python, and researching the AMI codes for the region we were deploying into.

However, simplicity although important as a driver for adoption, is not the true value of Terraform. Hashicorp’s Terraform is a very powerful deployment language, it is Cross-Platform, and Cross-Cloud/Environment. This in and of itself is a powerful proposition, even when using just the open source product.

The value of being able to write once and effectively deploy anywhere cannot be sniffed at. Simply by adding additional providers and changing a couple of lines, Terraform can shift entire application stacks from one infrastructure to another, effectively making hybrid and multi-cloud that much more attainable; a theme HashiCorp seems to be at the center of.

By upgrading from the OSS version to the enterprise version you gain the ability to provide collaboration on code between teams developers, automation, CI/CD. This coupled with a stringent policy and governance engine means that Operations can keep a very tight control of what is deployed by who, where and when, whilst keeping enough flexibility in the environment to keep even the most boisterous of developers happy.

In next week’s post on Terraform we will look at deploying a traditional three-tier application with all the relevant networking to an AWS VPC.

NEWSLETTER

Receive our top stories directly in your inbox!

Sign up for our Newsletters

LET'S CONNECT