Introduction to Terraform - Terraform Tutorial for Beginners

Introduction to Terraform - Terraform Tutorial for Beginners

In this post, we will take you through the Introduction to Terraform. This post will help you to understand the below topics.

Topics Covered:

  1. What is Infrastructure as a Code (IaC)?
  2. List of IaC Tools
  3. Introduction to Terraform
  4. Why should we use Terraform and Its Benefits?
  5. How Terraform works with Key Concepts
  6. Terraform Installation on Windows & Linux

You can also watch this entire tutorial on our youtube channel with demo.


What is Infrastructure as a Code (IaC)?

Infrastructure as Code (IaC) helps us to automates the infrastructure provisioning by using codes, scripts or any tools instead of creating the infrastructure manually. Anything you create with codes, files, scripts or using any tools, those will be considered as Infrastructure as Code (IaC).

We can provision, manage or destroy our entire infrastructure using Infrastructure as code (IaC). It enables our organization to completely develop, deploy and scale cloud applications with greater speed, less risk and reduced cost.

List of IaC Tools

Here are some of the most popular IaC Tools:
  1. Terraform
  2. AWS CloudFormation
  3. Azure Resource Manager
  4. Google Cloud Deployment Manager
  5. Ansible
  6. Chef
  7. Puppet
  8. SaltStack
  9. Vagrant

Introduction to Terraform?

Terraform is an open-source infrastructure as code (IaC) tool created by HashiCorp for automating or provisioning infrastructure easily.

Users has to create files, define resources, modules and provision entire data center infrastructure easily, securely and efficiently using declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON. 

Even Terraform can manage our existing and any popular service providers as well as custom in house solutions.

Why should we use Terraform and Its Benefits?

  • Infrastructure as Code (IaC) - Terraform Manages our entire infrastructure through codes, making our task easier to create, update and destroy it.
  • Consistency - Terraform ensure the same configuration defined in terraform files are applied across multiple environments like development, staging and production.
  • Automation - Terraform reduces human errors, syntax related issues and manual setup by automating infrastructure provisioning.
  • Version Control - Terraform has its inbuilt code tracking feature, so our infrastructure changes will be tracked in code, making easier to review and revert changes at any time.
  • Collaboration - Team members can work together on the same infrastructure configurations that improves collaboration from every team members and it increases the productivity.
  • Scalability - Using Terraform, We can easily scale our entire infrastructure up or down based on our project requirements.
  • Multi-Cloud - Terraform can manage the resources available across any different cloud providers from single terraform configuration.

How Terraform works with Key Concepts

  1. Create files: Firstly, Create our infrastructure resources in .tf files using HashiCorp Configuration Language (HCL).
  2. Terraform Init: Execute the command 'terraform init' to initialize the working directory and download the required providers plugins to connect with providers using API.
  3. Terraform Plan: Execute the command 'terraform plan' to validate and review the changes that is going to be affected before applying any changes. Its like a dry run.
  4. Terraform Apply: Execute the command 'terraform apply' to apply the desired changes to the infrastructure.
  5. Review State: Once applied, state files will be created for tracking the desired state. It will hold the current configuration state of the infrastructure.
  6. Terraform Destroy: Execute the command 'terraform destroy' to completely remove the infrastructure managed by Terraform codes.

Terraform Installation on Windows & Linux

Installing terraform is a straight forward procedure. We have to update the terraform official repository and we can install the terraform packages. I have provided the commands and instruction on how to install terraform on specific platforms.

How to Install Terraform on Ubuntu?

Download terraform gpg key, add terraform repository for the respective ubuntu releases and install terraform.
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform

How to Install Terraform on RHEL / CentOS?

Install required dependency packages and update terraform repository to install terraform.
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform

How to Install Terraform on Windows?

Step 1: Use the below official links to download the respective binary files based on your windows platform.


If link not worked, go to Terraform official website and download the respective binary file from the link directly.


Step 2: Unzip the downloaded zip file and copy the executable file to binary locations.
C:\Windows\System32
That's it for this post. Keep practicing and have fun. Leave your comments if any.

إرسال تعليق

0 تعليقات