DEV Community

Alexander Delgado
Alexander Delgado

Posted on • Updated on

What is Terraform?

Introduction

This post covers what Terraform is and what the benefits of using it are.

Terraform is a tool that allows you to define and create resources. The way that Terraform accomplishes this is the best part. Terraform uses easy to read statements with configuration data to create those resources.

Managing your resources this way is known as infrastructure as code. Instead of creating and managing resources and their configurations through interactive configuration tools you are now doing it through machine readable Terraform files.

Example

If you wanted to create a repository on GitHub using Terraform you would create a terraform file with the following in it:

provider "github" {
  token        = "${var.github_token}"
  organization = "${var.github_organization}"
}

resource "github_repository" "my_awesome_repo" {
  name        = "my_awesome_repo"
  description = "My awesome repo"
  private     = false
}

This is telling Terraform to create a GitHub repository with the name "my_awesome_repo" and a description "My awesome repo". When you apply this configuration Terraform will create that resource for you. Just like that!

Benefits

"Why Do I need this? I could easily script this using python or my favorite high level language."

That's true. Terraform, however, comes with many out-of-the-box features that you're not going to get by scripting the creation of resources yourself.

  • Terraform is able to keep state. It knows what resources you have created, what resources it'll need to create, which resources it needs to update, and which resources it will need to delete.

  • Terraform has a plan command that when ran will tell you exactly what resources will be created, modified, or deleted. This is really handy to ensure you're creating what you want to be creating and there are no surprises.

  • Terraform can graph your resources and tell you what resources have dependencies. This gives you, the operator, a lot of insight about your resources.

  • Terraform creates and modifies resources without dependencies in parallel to build infrastructure efficiently.

One of the biggest benefits that you get from Terraform is workflow portability. Whether you're working on resources in GitHub, BitBucket, AWS, Azure, DigitalOcean or anything else, your workflow looks the same no matter what service or provider you're working with.

  1. You create your Terraform configuration files
  2. You run terraform init to initialize the current directory
  3. You run terraform plan to see what resources will be created
  4. You run terraform apply to create those resources

Compare this to having to know where to look and how to configure each service that you're working on individually.

Terraform is awesome and comes with many benefits. I highly encourage anyone that is interested in infrastructure or devops to dive right in and start learning it as it is a great tool to have in your toolbox.

Resources & Learning More

Learning Terraform
Terraform Docs
A Comprehensive Guide to Terraform

Oldest comments (0)