Introduction to Terraform

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.

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.

Key features of Terraform:

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.

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]

How to Setup Terraform :

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.

Unzip the terraform package

extract the downloaded zip file. Here i downloaded the terraform zip file in C:\Users\devops\Downloads\. I extrated 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 tarraform 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.

Verify terraform version

using terraform version command you can see the terraform version. open command prompt in your system and enter terraform version command. it will give you the terraform version.

Let’s try terraform with AWS practically

Creating VPN on AWS using terraform

  1. create a main.tf file and write following code

2. execute commands terraform init -> terraform plan ->terraform apply

Outputs:

References :

Introduction — Terraform by HashiCorp

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Easy domain joins with Vagrant and Uplift project

Flutter Analysis and Practice: Integrated Architecture of Flutter and FaaS in the Cloud

Lambda Architecture at Boxever — Part 2

Creating my personal website with Astro, Tailwind CSS, and Nx

good blog

How I develop locally — Laragon

Laragon local development environment window

Site-to-Site IPSEC VPN on GCP/AWS with Strongswan

Kodi Fully Loaded Pc Download

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ishaan Singh

Ishaan Singh

More from Medium

PGP : how to encrypt your data ?

How does role-based access function in Dista

How do you overcome obstacles in Cloud Migration? Simple solutions.

Overcome cloud migration challenges

Data standards on the web: CoverageJSON