Introduction and Setup of Terrafrom on Ubuntu

Posted By :Harsh Kumar |25th March 2021

 

 

Terraform is a free open-source tool that is an Infrastructure as a code (IaC) software. It allows us to automate and manage infrastructure and services running on that infrastructure. It uses declarative language which is used to declare what we want to achieve. It is one of the best tools out there for Infrastructure provisioning.

 

In the scenario where one has to create infrastructures, and later on make some changes or delete some infrastructure, terraform is the tool you require. It makes all these processes pretty easy because of the reusable code of Terraform and tfstate file.

 

What is the tfstate file?

A tfstate file is created when we run terraform plan command. This file is basically stating the state or status of the resource at that exact time. It lets you track the changes from creating to destroying. So that when we plan next time, it will read the state file and know what is the state in the real world and try to match with that.

 

Parameters or Components of Terraform:

  1. Provider: They are basically IaaS e.g. AWS, GCP, Microsoft Azure, OpenStack), PaaS (e.g. Heroku), or SaaS services (e.g. Terraform Cloud, DNSimple, CloudFlare).
  2. Resource: They are under the Provider and are basically the entity that is going to be managed by Terraform. Eg Resource Group, VM, VNet, etc. In this, you can give the details (name, location, etc) or create tags.
  3. Output: is the data we want to get after the completion of script execution.

 

Major Steps in Script Execution:

 

  1. Initialise (terraform init): It just initialises and downloads all the plugins of the providers which are required. (For eg. In Azure: azurerm)
  2. Plan (terraform plan): It just shows what is going to happen before it actually happens.
  3. Apply (terraform apply): It also shows the plan from the last step and asks for confirmation from you.

Destroy (terraform destroy): Destroy means delete the resources.

 

Setup terraform on ubuntu

 

Step1. Add Terraform key.

$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add –

Step2. Add repository

$ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

Step3. Install Terraform

$ sudo apt-get update && sudo apt-get install terraform

Step3. Verify the installation by running the command:

$ terraform -help

About Author

Harsh Kumar

He is an enthusiastic employee who has worked on cloud platforms like Azure and AWS and some DevOps tools.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us