Introduction to Terraform
By: Anubhav Singh
Tags: 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.

Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.

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, etc.

Sample Terraform script for creating VPN on AWS:

There are few reasons that why developers terraform instead of using other infrastructure as code tools:

● Open source: Terraform is backed by large communities of contributors who build plugins to the platform. Regardless of which cloud provider you use, it’s easy to find plugins, extensions, and professional support. This also means Terraform evolves quickly, with new benefits and improvements added consistently.

● Platform agnostic: Meaning you can use it with any cloud services provider. Most other IaC tools are designed to work with single cloud provider.

Download Terraform

download the terraform from official terraform website https://www.terraform.io/downloads.html

you can see the windows 32 bit and 64 bit source files. download depends on your system here i am downloading 64 bit terraform. it will be downloaded as zip file.

● How To Install Terraform on Linux Servers

Unzip the terraform package

extract the downloaded zip file. Here Idownloaded the terraform zip file in C:\Users\devops\Downloads\. I extracted the zip file, after extracting the zip file you can see terraform.exe file in C:\Users\devops\Downloads\terraform_0.12.23_windows_amd64

This is the workspace path of your terraform in your system or you can say the path of terraform.exe.

Configure environment variables for terraform

Go to environment variables in advanced system settings your windows 10 or 8 or 7. In system variables you can see “path” select path and click on edit and add path of terraform i.e. C:\Users\devops\Downloads\terraform_0.12.23_windows_amd64

That’s it we have successfully configured terraform on windows 10 or 8 or 7.

Some Basic commands of Terraform:

Terraform init: The terraform init command is used to initialize the working directory in which the terraform configuration files are present these files includes such as main.tf, variables.tf etc. This is the first command that should be run after writing a new terraform configuration or cloning an existing one from version control.

Command: terraform init [options] [dir]

Terraform plan: The terraform plan command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.

Command: terraform plan [options] [dir]

Terraform plan: The terraform plan command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.

Command: terraform plan [options] [dir]

Terraform plan: The terraform plan command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.

Command: terraform plan [options] [dir]

Terraform plan: The terraform plan command is used to create an execution plan. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.

Command: terraform plan [options] [dir]

Terraform apply: The terraform apply command is used to apply the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by a terraform plan execution plan.

Command: terraform apply [options] [dir-or-plan]

Terraform import: The terraform import command is used to import existing resources into Terraform.

Command: terraform import [options] ADDRESS_ID

Terraform destroy: The terraform destroy command is used to destroy the Terraform-managed infrastructure.

Command: terraform destroy [options] [dir]