Skip to main content

Terraform: Orchestrate Multi-Platform Cloud Deployments

The elasticity and scalability of the cloud provide lots of opportunity for automation. Some automation tools and services are provided by cloud vendors themselves. AWS, for example, offers CloudFormation for provisioning AWS resources programmatically, Microsoft has its Automation, and OpenStack has Heat. But all those services come with vendor lock: they’ll only deploy within their own environments. But if you’re looking for multi-vendor solutions, then you might be better off with HashiCorp’s open source Terraform, which can provision servers and services from just about any cloud platform.

Besides Terraform, HashiCorp is also the creator of the Vagrant, Packer, Serf, and Consul projects, and the commercial product Atlas.

Use Terraform to launch your application infrastructure

Terraform is meant to help you combine all the components you’ll need to build and launch your application infrastructure. You could, for instance, select a base server from AWS, DNS from cloudfare, and a postgres database from Heroku. Terraform will build a single application framework from across all these providers in parallel.

Terraform infrastructure

When you make changes to your configuration file, Terraform determines what needs updating and applies only incremental changes.

  • Infrastructure as Code:

     Your complete infrastructure and services are defined using programmatically and versioned code. Code-defined infrastructure is generally easier to read and share with others.

  • Execution Plans:

    The execution plan shows exactly what will happen when you apply a particular Terraform configuration, giving you clear visibility into the way your infrastructure will perform.

  • Resource Graph:

    After your infrastructure has been built by Terraform, you can visualize your resources and gain insight into their dependencies.

Terraform dependencies

Terraform Use Cases

Terraform’s flexibility and power mean that it will work across a very wide range of use cases.

  • Multi-tier applications:

A two-tier app uses a web/application server that’s powered by standalone database servers. Terraform will make sure that your database tier is available before the web servers are started and before attaching web nodes to a load balancer. A web or database tier can be easily scaled by modifying a single count configuration value.

  • Multi-cloud deployment:

You may want to deploy your application across multiple platforms for fault tolerance or disaster recovery.  While many infrastructure orchestration tools are cloud vendor specific, Terraform is cloud-agnostic. By using a single configuration file, you can deploy your application on resources from multiple cloud providers.

  • Heroku app setup:

We addressed the what is Heroku? question in a previous post. Terraform can be used to codify the Heroku application set up the process, ensuring that all required add-ons (like configuring DNSimple to create a CNAME record or setting up cloudfare as your CDN) are available.

  • Software demos:

You can provide a sample Terraform configuration file to create, provision and bootstrap a demo on cloud providers like AWS to your end users and clients, who could also quickly tweak resource parameters according to their needs.

  • Disposable environments:

In an SDLC process you will create environments like QA, Staging, Load Testing, and Production. Some of these environments don’t always have to be running. As your Terraform-based infrastructure is code-based, you can easily build and destroy your infrastructure according to need.

  • Identical environments:

If you need reliably reproducible environments across your application life cycle, Terraform configurations can be dropped in (and out) on demand to build staging, QA or dev deployments.

  • Software Defined Networking:

AWS VPCs, for example, are among the most commonly used SDN implementations and can be codified by Terraform.

Installing Terraform (Linux)

Here’s how you can very quickly and simply install Terraform on your Linux system. There are also 32 and 64-bit packages available for Mac OS X, Windows, FreeBSD, and OpenBSD.

  • Download the appropriate package for your OS.
  • Add Terraform to your system path.
    export PATH=$PATH:/Users/nitheesh/terraform_0.6.3_darwin_amd64
  • Verify the installation by typing terraform on your command prompt

Terraform installation verification on command prompt
The following cloud providers are supported by Terraform:

  • Amazon Web Services
  • Microsoft Azure
  • Google Cloud
  • Heroku
  • OpenStack
  • Docker
  • Cloudstack

Deploying a two-tier application on AWS using Terraform

Now that Terraform is installed on your Linux system, use this simple “terraform init” example from your command prompt to quickly deploy a two-tier application to AWS (note: you may incur usage costs from AWS as a result).

terraform init github.com/hashicorp/terraform/examples/aws-two-tier

To generate and show an execution plan, run

terraform plan

cd into your git-cloned directory and then run

terraform apply

Terraform will interactively ask for account authentication and access data like your AWS Keys, Region, and AMI. Your resources will be provisioned on AWS and a sample nginix application will be deployed on those servers.

When  you  are done, clean up your resources by running

terraform destroy

If you’d like to learn more on Terraform, this is your go-to learning material on the topic:

Solving Infrastructure Challenges with Terraform Learning Path 

Create AWS Resources with Terraform hands-on Lab 

Do you have your own experiences with or plans for Terraform? Let us hear from you in the comments.

Written by

Nitheesh Poojary

My professional IT career began nine years back when I was just out of my college. I worked with a great team as an infrastructure management engineer, managing hundreds of enterprise application servers. I found my passion when I got the opportunity to work with Cloud technologies: I'm addicted to AWS Cloud Services, DevOps engineering, and all the cloud tools and technologies that make engineers' lives easier. Currently, I am working as a Solution Architect in SixNines IT. We are an experienced team of engineers that have helped hundreds of customers move to the cloud responsibly. I have achieved 5 AWS certifications, happily helping fellow engineers across the globe through my blogs and answering questions in various forums.

Related Posts

Joe Nemer
Joe Nemer
— April 1, 2019

AWS EC2 Instance Types Explained

Amazon Web Services’ resource offerings are constantly changing, and staying on top of their evolution can be a challenge. Elastic Cloud Compute (EC2) instances are one of their core resource offerings, and they form the backbone of most cloud deployments. EC2 instances provide you with...

Read more
  • AWS
  • EC2
Sanket Dangi
— February 11, 2019

WaitCondition Controls the Pace of AWS CloudFormation Templates

AWS's WaitCondition can be used with CloudFormation templates to ensure required resources are running.As you may already be aware, AWS CloudFormation is used for infrastructure automation by allowing you to write JSON templates to automatically install, configure, and bootstrap your ...

Read more
  • AWS
  • formation
Andrew Larkin
— January 24, 2019

The 9 AWS Certifications: Which is Right for You and Your Team?

As companies increasingly shift workloads to the public cloud, cloud computing has moved from a nice-to-have to a core competency in the enterprise. This shift requires a new set of skills to design, deploy, and manage applications in cloud computing.As the market leader and most ma...

Read more
  • AWS
  • AWS certifications
Andrew Larkin
— November 28, 2018

Two New EC2 Instance Types Announced at AWS re:Invent 2018 – Monday Night Live

The announcements at re:Invent just keep on coming! Let’s look at what benefits these two new EC2 instance types offer and how these two new instances could be of benefit to you. If you're not too familiar with Amazon EC2, you might want to familiarize yourself by creating your first Am...

Read more
  • AWS
  • EC2
  • re:Invent 2018
Guy Hummel
— November 21, 2018

Google Cloud Certification: Preparation and Prerequisites

Google Cloud Platform (GCP) has evolved from being a niche player to a serious competitor to Amazon Web Services and Microsoft Azure. In 2018, research firm Gartner placed Google in the Leaders quadrant in its Magic Quadrant for Cloud Infrastructure as a Service for the first time. In t...

Read more
  • AWS
  • Azure
  • Google Cloud
Khash Nakhostin
Khash Nakhostin
— November 13, 2018

Understanding AWS VPC Egress Filtering Methods

In order to understand AWS VPC egress filtering methods, you first need to understand that security on AWS is governed by a shared responsibility model where both vendor and subscriber have various operational responsibilities. AWS assumes responsibility for the underlying infrastructur...

Read more
  • Aviatrix
  • AWS
  • VPC
Jeremy Cook
— November 10, 2018

S3 FTP: Build a Reliable and Inexpensive FTP Server Using Amazon’s S3

Is it possible to create an S3 FTP file backup/transfer solution, minimizing associated file storage and capacity planning administration headache?FTP (File Transfer Protocol) is a fast and convenient way to transfer large files over the Internet. You might, at some point, have conf...

Read more
  • Amazon S3
  • AWS
Guy Hummel
— October 18, 2018

Microservices Architecture: Advantages and Drawbacks

Microservices are a way of breaking large software projects into loosely coupled modules, which communicate with each other through simple Application Programming Interfaces (APIs).Microservices have become increasingly popular over the past few years. The modular architectural style,...

Read more
  • AWS
  • Microservices
Stuart Scott
— October 2, 2018

What Are Best Practices for Tagging AWS Resources?

There are many use cases for tags, but what are the best practices for tagging AWS resources? In order for your organization to effectively manage resources (and your monthly AWS bill), you need to implement and adopt a thoughtful tagging strategy that makes sense for your business. The...

Read more
  • AWS
  • cost optimization
Stuart Scott
— September 26, 2018

How to Optimize Amazon S3 Performance

Amazon S3 is the most common storage options for many organizations, being object storage it is used for a wide variety of data types, from the smallest objects to huge datasets. All in all, Amazon S3 is a great service to store a wide scope of data types in a highly available and resil...

Read more
  • Amazon S3
  • AWS
Cloud Academy Team
— September 18, 2018

How to Optimize Cloud Costs with Spot Instances: New on Cloud Academy

One of the main promises of cloud computing is access to nearly endless capacity. However, it doesn’t come cheap. With the introduction of Spot Instances for Amazon Web Services’ Elastic Compute Cloud (AWS EC2) in 2009, spot instances have been a way for major cloud providers to sell sp...

Read more
  • AWS
  • Azure
  • Google Cloud
  • SpotInst
Guy Hummel and Jeremy Cook
— August 23, 2018

What are the Benefits of Machine Learning in the Cloud?

A Comparison of Machine Learning Services on AWS, Azure, and Google CloudArtificial intelligence and machine learning are steadily making their way into enterprise applications in areas such as customer support, fraud detection, and business intelligence. There is every reason to beli...

Read more
  • AWS
  • Azure
  • Google Cloud
  • Machine Learning