Getting started with Terraform

Learn to setup Terraform on your workstation in this step-by-step guide.

Photo

Photo by Firdouss Ross on Unsplash

What is Terraform?

Terraform is an open-source tool allows to build, change and version our infrastructure in an easy and efficient way. It uses declarative language HCL (Hashicorp Configuration Language) to define infrastructure as code.

Terraform concepts

Let’s quickly learn about some concepts in Terraform.

  • Providers
    Terraform Providers enables interaction with APIs and handle authentication of different IaaS(e.g. Google Cloud Platform, Amazon Web Service, Azure) or SaaS(e.g. CloudFlare). There are many Terraform supported providers already available and a full list can be seen here.

  • Resource
    Terraform Resource is a very important component. Each resource block describes the infrastructure object(e.g. VM instance, Storage buckets, DNS records, Cloud NAT).

  • Modules
    Terraform modules are the collection of resources defined in a way that can be reused.

  • Data Sources
    Terraform Data Sources help to read infrastructure which is created using (or without using) Terraform.

  • State
    Terraform State stores information about the infrastructure created by Terraform code. It is used by Terraform to detect changes in the resources defined in the code.

Terraform state is stored on local machine by default in the name of terraform.tfstate but can be stored remotely on systems like Google Cloud Storage(GCS), AWS S3.

Let’s setup Terraform

Below steps are for Linux based system. For MAC, download the relevant package and the rest of the steps should be the same.

  1. Download the latest terraform package from terraform.io/downloads.

    export TF_VERSION=0.12.16
    wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip -O /tmp/terraform.zip
  2. Unzip the terraform binary to a directory which is included in your system PATH.

    sudo unzip /tmp/terraform.zip -d /usr/local/bin/
  3. Reload your shell.

    exec -l $SHELL
  4. Verify installation.

    terraform --help

Below is the terminal recording:

Hope this blog help you get started quickly with Terraform.

If you have feedback or questions, please reach out to me on LinkedIn or Twitter