{{announcement.body}}
{{announcement.title}}

Getting Started with Terraform

DZone 's Guide to

Getting Started with Terraform

This brief tutorial outlines some of the components of Terraform and demonstrates how to get it installed locally.

· Cloud Zone ·
Free Resource

In this blog, you will learn to set up Terraform on your workstation in this step-by-step guide.  

What is Terraform?

Terraform is an open-source tool allows us to build, change, and version our infrastructure in an easy and efficient way. It uses the 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 enable interaction with APIs and handles authentication of different IaaS services like Google Cloud Platform and Amazon Web Service, or SaaS services like 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, or 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.

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

Terraform Setup

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.24
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip -O /tmp/terraform.zip
  1. Unzip the terraform binary to a directory which is included in your system PATH.
sudo unzip /tmp/terraform.zip -d /usr/local/bin/
  1. Reload your shell.
exec -l $SHELL
  1. Verify installation.
terraform --help


Terminal Recording

I hope this blog helps you to quickly get started with Terraform.

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

Originally published at pbhadani.com

Topics:
devops, hashicorp, infrastructure as code, installation, terraform, terraform tutorial

Published at DZone with permission of Pradeep Bhadani . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}