Sign In
Sign In

Installing Terraform: Step-by-Step Guide

Installing Terraform: Step-by-Step Guide
Hostman Team
Technical writer
Terraform
02.11.2024
Reading time: 5 min

Terraform is an infrastructure management tool from HashiCorp that enables the deployment and management of infrastructure across various cloud platforms. Its main advantage is its ability to automate the creation and management of infrastructure, making it an essential tool for DevOps engineers and system administrators. This guide covers the steps to install Terraform on both Windows and Ubuntu.

What Terraform Is and How It Works

Terraform automates infrastructure deployment and management in cloud environments. It manages a variety of resources—such as virtual machines, networks, and data storage—through a single tool.

Terraform uses configuration files written in HashiCorp Configuration Language (HCL) to describe the infrastructure to be created. These HCL files let users specify the infrastructure setup, including all resources required. For example, in a configuration file, you can describe a virtual machine with specific attributes, a database, or any other service you want to provision.

When you run Terraform, it reads these configuration files and creates the resources described within them. Terraform considers dependencies between resources and creates them in the correct order.

If the user changes the Terraform configuration—for instance, by adding a new resource or modifying an existing one—Terraform identifies the necessary adjustments to bring the infrastructure to the desired state as described in the configuration files.

One of Terraform’s main benefits is its ability to manage infrastructure across different cloud environments with a single tool. This flexibility simplifies moving infrastructure between cloud platforms and streamlines infrastructure management overall.

Installing Terraform on Windows

There are several ways to install Terraform on Windows, including:

  • Using a package manager like Chocolatey
  • Manual installation

Here’s a guide for both methods.

Installation Using Chocolatey

Chocolatey is a package manager for Windows that allows software installation, updates, and management from the command line.

If Chocolatey is not yet installed, follow the guide on its official website. Once installed, you can install software from the command line using choco install. Here’s the syntax:

choco install <package_name>

To install Terraform with Chocolatey:

  1. Open the command prompt as an administrator from the Start menu.

  2. Run the installation command:

choco install terraform
  1. After the installation, you can verify it with terraform -v:

C:\Windows\system32>terraform -v
Terraform v1.3.6
on windows_amd64

Manual Installation

One drawback of using a package manager is the possibility of downloading an outdated version. For the latest version, consider installing Terraform manually.

To do this:

  1. Visit the HashiCorp website and download the appropriate version for your system.

  2. Extract the contents to a preferred folder, such as C:\Terraform.

  3. Note that the Terraform command won’t work directly from the command line without the full path unless added to your system path.

C:\Windows\system32>terraform -v
'terraform' is not recognized as an internal or external command,
operable program or batch file.

C:\Windows\system32>C:\Terraform\terraform -v
Terraform v1.3.6
on windows_amd64

To make Terraform accessible directly from the command line, add it to the system PATH:

  1. Open Control Panel and go to System and Security.

  2. In the System section, click on Advanced System Settings.

  3. In the System Properties window, go to the Advanced tab.

  4. Click Environment Variables.

  5. In the System Variables section, find the PATH variable and click Edit.

  6. Click New in the Edit Environment Variable window and add the path to the folder where you extracted Terraform (e.g., C:\Terraform).

  7. Click OK.

Verify the installation in the command prompt:

terraform -v
Terraform v1.3.6
on windows_amd64

Installing Terraform on Ubuntu

To install Terraform on Ubuntu, follow these steps:

Step 1: Open the terminal and update the package list:

sudo apt update

Step 2: Install necessary packages for downloading and installation:

sudo apt install wget unzip

Step 3: Navigate to the directory where you want to install Terraform, for example:

cd ~

Step 4: Download the latest version from HashiCorp’s website:

wget https://releases.hashicorp.com/terraform/0.x.x/terraform_0.x.x_linux_amd64.zip

Replace 0.x.x with the desired version. A list of available versions can be found on the Terraform release page.

Step 5: Unzip the downloaded archive:

unzip terraform_0.x.x_linux_amd64.zip

Step 6: Move the extracted file to /usr/local/bin to make it accessible system-wide:

sudo mv terraform /usr/local/bin/

Step 7: Verify that Terraform is installed and accessible by checking its version:

terraform -v

You should see the Terraform version you installed. Terraform is now ready for use.

Advantages of Terraform

Terraform offers several advantages for infrastructure management:

  • Automation: Infrastructure is described in configuration files, simplifying deployment and management.

  • Unified Configuration Language: Terraform uses a single configuration language, making it possible to manage infrastructure across different cloud environments with one tool.

  • Dependency Management: Terraform allows you to define dependencies between resources, helping manage the order in which resources are created or destroyed.

  • Rollback Capability: Terraform tracks infrastructure changes, enabling you to roll back updates if needed.

Conclusion

Terraform is a powerful cloud infrastructure management tool. It lets you create, modify, and delete resources across multiple cloud providers using a single configuration language, which offers convenience, speed, and consistency in infrastructure management. Additionally, you can back up configurations and manage changes through version control tools.

Terraform
02.11.2024
Reading time: 5 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us