Open In App

How To Install Terraform In Ubuntu

Terraform is an open-source infrastructure as code (IaC) tool that enables users to define and provision infrastructure using a declarative configuration language. It simplifies the process of managing and scaling infrastructure by allowing you to describe your infrastructure necessities in a configuration file. In this article, you will get to know about Terraform, and why we need Ubuntu to install Terraform, we will also discuss major issues that you will face during installation and methods to resolve them.

What is Terraform?

Terraform is an open-source infrastructure as Code ( IaC ) tool that is developed by HashiCorp. It facilitates the users to define and provision the infrastructure using declarative configuration files. Its components such as servers, databases, and networks managed as code allowing version control and automation of the entire infrastructure lifecycle.

Why Use Ubuntu to install Terraform?

Terraform can be set up on various operating systems, like Windows, macOS, and different Linux distributions. Choosing Ubuntu to install Terraform is not a basic requirement, However, it has certain key features which differentiate it from other Linux distributions. The benefits of Ubuntu are illustrated below:



How to Manually Install Terraform in Ubuntu? A Step-By-Step Guide

The following are the steps to install the terraform in ubuntu:

Step 1: Search for the latest version

Step 2: Go into Command Prompt

mkdir terraform

cd terraform/

Step 3: 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

Step 4: Verifying the Terraform Installation

You can check the installed version by using this command

terraform --version

How to Configure Terraform In Ubuntu? A Step-By-Step Guide

The following are the steps for configuring the terraform in ubuntu:

Step 1: Download Terraform

Step 2: Extract the Binary

Step 3: Set Permissions

 chmod +x /usr/local/bin/terraform

Step 4: Verify Terraform Installation

Now, verify the installation of terraform using the following command:

terraform version

Step 5: Setup Environment Variables ( Optional )

echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc
source ~/.bashrc

How to Create Terraform Configuration Files? A Step-By-Step Guide

The following are the steps for configuring Terraform files:

Step 1: Create A Directory

mkdir terraform-project
cd terraform-project

Step 2: Initailize Terraform

terraform init

Step 3: Create A Configuration File

Create a new Terraform configuration file with .tf extension, such as main.tf with following command:

touch main.tf

Step 4: Write Configuration

Step 5: Validate the Confguration

terraform validate

Step 6: Plan Infrastructure

terraform plan

Step 7: Apply Changes

terraform apply

Step 8: Review Changes

After apply the changes with the above step, review the changes once, provide the configuration with typing yes as prompted.

Step 9: Verify Resources

terraform show

How To Update Terraform Version In Ubuntu? A Step-By-Step Guide

The following are the steps for updating terraform version in ubuntu:

Step 1: Download the New Version

Step 2: Extract the Binary

sudo mv terraform /usr/local/bin/

Step 3: Move the Binary to Bin Directory

sudo mv terraform /usr/local/bin

Step 4: Update Permissions

sudo chmod +x /usr/local/bin/terraform

Step 5: Verify the Update

terraform version

Troubleshooting Common Issues of Terraform

1. Insufficient Permissions

sudo mv terraform /usr/local/bin/

2. Dependency Issues

sudo apt-get install -y unzip

3. Incorrect PATH Configuration

echo 'export PATH=$PATH:/usr/local/bin/' >> ~/.bashrc
source ~/.bashrc

4. Outdated Terraform Version

terraform version -check-upgrade

Conclusion

You can successfully install terraform in the ubuntu by following above given Steps. This tutorial will not help in installation but also will provide you information about brief knowledge of terraform and issues which you might can face during installation.

Installation of Terraform In Ubuntu – FAQs

What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool designed to outline, provision, and control infrastructure throughout numerous cloud servers and on-premise environments.

Can I Use Terraform With Multiple Cloud Providers?

Yes, Terraform is cloud-agnostic and it helps more than one cloud provider. You can manage resources on AWS, Azure, Google Cloud, etc. within the same Terraform configuration.

Can I Use Terraform to ,anage Already Existing Infrastructure?

Yes, Terraform can be used to manage each current and new infrastructure. You can import present resources into Terraform and manage them using the Terraform configuration.

What Is The Difference Between `terraform init`, `terraform plan`, and `terraform apply`?

Terraform init: Initializes a new or current Terraform configuration.

Terraform plan: Generates an execution plan, showing what actions Terraform will take.

Terraform apply: Applies the adjustments described within the Terraform configuration to the actual infrastructure.

What is HCP Terraform?

HCP Terraform is service within the Hasicorp Cloud Platform (HCP) provides the infrastructure as Code using Terraform.

What is Configuration Language?

Configuration is a language refers to the syntax that is used in terraform files for defining and managing the infrastructure resources.

How do I know if Terraform is installed?

On using the following command we can verify the installation of terraform:

terraform --version

How do I Install Terraform in Ubuntu Terminal?

For this firstly download the terraform software and then the following command to install the terraform in ubuntu:

sudo apt-get install terraform

How do I run a Terraform script in Ubuntu?

For running a terraform script, navigate to the directory where the configuration files are defined:

terraform init
terrform apply

Article Tags :