Introduction to Terraform

In this blog post, I’m going to introduce you to Terraform which is a declarative, infrastructure as code developed by HashiCorp. I’ll cover what Terraform is, what it can do, and how you can start using it today. I’ll also have an accompanying webinar where I’ll walk you through getting started with Terraform so be on the lookout for that!

What is Terraform?

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. Terraform uses configuration files to describe what it will do to achieve its goal, and then executes it to build the described infrastructure. Terraform will never do anything that isn’t declared within the configuration files so remember to be as specific as possible. Next, let’s look at what comprises terraform.

Main Features

Infrastructure as Code

Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.

Execution Plans

Terraform has a “planning” step where it generates an execution plan. The execution plan shows what Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure.

Resource Graph

Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.

Change Automation

Complex changesets can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph, you know exactly what Terraform will change and in what order, avoiding many possible human errors.

What can Terraform do?

The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features and others. Popular use cases include Heroku App Setup, Multi-Tier Applications, Self Service Clusters, Software Demos, Disposable Environments, Software Defined Networking, Resource Schedulers and Multi-Cloud Deployments. If you wish to know more, check out this Use Cases page from HashiCorp to see more in depth overview of each example.

Terraform is changing the way infrastructure is managed, and making it faster and more efficient to execute DevOps projects. It focuses on the automation of the infrastructure itself, which has the effect of allowing teams to execute a DevOps model faster and more efficiently. Terraform also allows teams such as operations and security to work in parallel with developers. Each element in the DevOps process has a specifically designed tool, which means teams can focus on their particular tasks without blocking other teams working on the project. This transforms the DevOps process from a linear and slow waterfall-type project into one where teams can work in parallel.

Get Started with AWS

Now I’m going to quickly walk you through how to use Terraform with Amazon Web Service.

  1. Install Terraform on Mac, Linux, or Windows by downloading the binary or using a package manager (Homebrew or Chocolatey). Then create a Docker container locally by following a quick-start tutorial to check that Terraform installed correctly.
  2. Authenticate to AWS, and create an EC2 instance under the AWS free tier. You will write and validate Terraform configuration, initialize a configuration directory, and plan and apply a configuration to create infrastructure.
  3. Modify EC2-instance configuration to use a different Ubuntu version. Plan and apply the changes to re-provision a new instance that reflects the new configuration. Learn how Terraform handles infrastructure change management.
  4. Completely destroy the AWS infrastructure that Terraform manages in a configuration with a single command. Evaluate the plan and confirm the destruction.
  5. Create an implicit dependency between an EC2 instance and its elastic IP using variable interpolation. Create an explicit dependency on an S3 bucket using terraform configuration. Learn how Terraform creates independent resources in parallel.
  6. Configure, install software, and run scripts on infrastructure you create with Terraform. Write data to a local file, install NGINX on a remote EC2 instance, and manually taint a resource where a provisioner has failed.
  7. Declare your AWS region as a variable. Reference the variable in Terraform configuration. Define variables using command line flags, environment variables, .tfvars files or default values.
  8. Declare output variables to display the public IP address of an EC2 instance. Display all outputs and query specific outputs. Define what data stored in Terraform state is relevant to the operator or end user.
  9. Configure Terraform to store state in Terraform Cloud remote back-end. Add a remote state block directly to configuration or set an environment variable to load remote state configuration when Terraform initializes.

In all, the entire process should take you about an hour or so to complete. In my webinar, I’ll be going over how to get started with Terraform and Apache Cassandra on AWS.


Cassandra.Link is a knowledge base that we created for all things Apache Cassandra. Our goal with Cassandra.Link was to not only fill the gap of Planet Cassandra, but to bring the Cassandra community together. Feel free to reach out if you wish to collaborate with us on this project in any capacity.

We are a technology company that specializes in building business platforms. If you have any questions about the tools discussed in this post or about any of our services, feel free to send us an email!

Photo by Farzad Nazifi on Unsplash