Terraform Tutorial: Basics to Advanced for DevOps Engineer— Part 1

Saurabh khan
4 min readJun 5, 2023

--

Introduction

Are you a DevOps engineer looking for an efficient way to manage your cloud infrastructure? Look no further than Terraform! This open-source Infrastructure-as-Code (IaC) tool allows you to provision and manage cloud resources with ease, making it a must-have in any DevOps toolkit.

What is Terraform?

Terraform is an infrastructure as code (IaC) tool that allows DevOps engineers to define and manage their infrastructure in a declarative manner. This means that instead of manually configuring servers, databases, and other resources, engineers can use code to define their infrastructure, making it easier to manage and scale. Terraform supports multiple cloud providers, including AWS, Azure, Google Cloud Platform, and more.

How does Terraform work?

Terraform works by defining infrastructure in code using a configuration language called HashiCorp Configuration Language (HCL). Engineers define the resources they want to create, such as virtual machines, databases, or load balancers, and Terraform creates them in the cloud provider of their choice. Once the infrastructure is created, Terraform can also manage updates and changes to the infrastructure as needed.

Why is Terraform important for DevOps teams?

Terraform has become an essential tool for DevOps teams because it simplifies the process of managing infrastructure. By defining infrastructure in code, engineers can easily version control and collaborate on their infrastructure changes. Additionally, Terraform provides a consistent workflow across multiple cloud providers, making it easier for teams to manage their infrastructure regardless of the cloud provider they use.

https://gravitydevops.com/kubernetes-tutorial-basics-to-advanced/

https://gravitydevops.com/devops-engineer-and-sre-roadmap/

https://gravitydevops.com/introduction-to-aws-devops/

https://gravitydevops.com/a-deep-dive-into-azure-devops/

https://gravitydevops.com/devops-engineer-salary/

https://gravitydevops.com/linux-for-devops-engineer/

How to install Terraform on Linux

Here is a step-by-step guide on how to install Terraform on Linux.

  1. Download the Terraform binary package suitable for your Linux distribution and architecture. You can find the latest version of Terraform and the corresponding download links on the official Terraform website: https://www.terraform.io/downloads.html
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


Note: This is for Ubuntu and Debian.

2. Extract the downloaded file to a directory of your choice. You can use the following command to extract the file:

$ unzip terraform.zip

3. Move the extracted binary file to a directory in your system’s PATH so that you can run Terraform from any directory. You can use the following command to move the file:

$ sudo mv terraform /usr/local/bin/

4. Verify that Terraform is installed correctly by running the following command:

$ terraform --version

This should display the version of Terraform that you just installed.

Congratulations! You have successfully installed Terraform on Linux.

How to install Terraform on Windows

  1. Download the latest version of Terraform from the official website. Make sure to choose the correct version for your system architecture (32-bit or 64-bit). Link- https://developer.hashicorp.com/terraform/downloads
  2. Extract the downloaded file to a directory of your choice. You can use any file extraction software like WinZip, 7-Zip, or WinRAR.
  3. Add the extracted binary file to your system’s PATH so that you can run Terraform from any directory. To do this, follow these steps:

a. Open the Start menu and search for “environment variables”.

b. Click on “Edit the system environment variables”.

c. Click on the “Environment Variables” button.

d. Under “System Variables”, find the “Path” variable and click on “Edit”.

e. Click on “New” and add the path to the directory where you extracted the Terraform binary file.

f. Click “OK” to close all the windows.

4. Open a new command prompt window and verify that Terraform is installed correctly by running the following command:

terraform --version

This should display the version of Terraform that you just installed.

Congratulations! You have successfully installed Terraform on Windows.

How to install terraform on MacOS

Here is a step-by-step guide on how to install Terraform on macOS.

  1. Install Homebrew, a package manager for macOS. You can install it by running the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. After Homebrew is installed, run the following command to install Terraform:

brew install terraform

3. Verify that Terraform is installed correctly by running the following command:

terraform --version

This should display the version of Terraform that you just installed.

Congratulations! You have successfully installed Terraform on macOS using Homebrew.

Follow for such content and part 2 will cover the basic of the Terraform.

HAPPY LEARNING SIUUUU

--

--

Saurabh khan
Saurabh khan

Written by Saurabh khan

Azure | AWS | GCP | DevOps | Linux | Git & GitHub | Docker | K8s | Python | Nagios https://gravitydevops.com

No responses yet