TerraformPilot

Technology

How to Install Terraform on Red Hat Enterprise Linux

Step-by-step guide to install Terraform on RHEL using YUM. Configure HashiCorp repository and verify installation. Step-by-step guide with code examples and ...

LLuca Berton2 min read

Introduction

#

Terraform, a widely-used Infrastructure as Code tool, can be a game changer for your DevOps workflow. This article provides a step-by-step guide on how to install Terraform on Red Hat Enterprise Linux (RHEL) 9.3, ensuring a smooth setup for your infrastructure management.

Terraform and RHEL

#

Terraform by HashiCorp is an open-source tool that allows you to define and provision a datacenter infrastructure using a high-level configuration language. Red Hat Enterprise Linux (RHEL) is a popular and robust operating system, known for its stability and enterprise-level support, making it an excellent choice for running Terraform.

Prerequisites

#
  • Access to a RHEL 9.3 system
  • Sudo privileges
  • Internet connectivity

Installation Steps

#

1. Access Your RHEL System

#

Start by SSH-ing into your RHEL server:

ssh devops@rhel.example.com

Enter your password when prompted.

ssh devops@rhel.example.com
devops@rhel.example.com's password:
Activate the web console with: systemctl enable --now cockpit.socket
[devops@localhost ~]$

2. Switch to Root User

#

For installing packages system-wide, switch to the root user:

sudo su

Enter the sudo password for the 'devops' user.

[devops@localhost ~]$ sudo su
[sudo] password for devops:
[root@localhost devops]#

3. Verify RHEL Version

#

It's good practice to check your operating system details:

cat /etc/os-release

This confirms that you are running RHEL 9.3.

NAME="Red Hat Enterprise Linux"\
VERSION="9.3 (Plow)"\
ID="rhel"\
ID_LIKE="fedora"\
VERSION_ID="9.3"\
PLATFORM_ID="platform:el9"\
PRETTY_NAME="Red Hat Enterprise Linux 9.3 (Plow)"\
ANSI_COLOR="0;31"\
LOGO="fedora-logo-icon"\
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"\
HOME_URL="https://www.redhat.com/"\
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9"\
BUG_REPORT_URL="https://bugzilla.redhat.com/"
 
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"\
REDHAT_BUGZILLA_PRODUCT_VERSION=9.3\
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"\
REDHAT_SUPPORT_PRODUCT_VERSION="9.3"

4. Install Yum-Utils

#

Yum-Utils provides utilities that integrate with Yum to enhance its default features, making it easier to manage packages.

yum install yum-utils

Confirm the installation by typing 'y' when prompted.

Dependencies resolved.
===============================================================================================
 Package         Architecture Version               Repository                            Size
===============================================================================================
Installing:
 yum-utils       noarch       4.3.0-11.el9_3        rhel-9-for-aarch64-baseos-rpms        45 k
 
Transaction Summary
===============================================================================================
Install  1 Package
 
Total download size: 45 k
Installed size: 23 k
Is this ok [y/N]: y
Downloading Packages:
yum-utils-4.3.0-11.el9_3.noarch.rpm                             35 kB/s |  45 kB     00:01
-----------------------------------------------------------------------------------------------
Total                                                           35 kB/s |  45 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                       1/1
  Installing       : yum-utils-4.3.0-11.el9_3.noarch                                       1/1
  Running scriptlet: yum-utils-4.3.0-11.el9_3.noarch                                       1/1
  Verifying        : yum-utils-4.3.0-11.el9_3.noarch                                       1/1
Installed products updated.
 
Installed:
  yum-utils-4.3.0-11.el9_3.noarch
 
Complete!

5. Add the HashiCorp Repository

#

HashiCorp provides a dedicated repository for their packages. Add it to your system:

yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

The output look like the following:

Updating Subscription Management repositories.
Adding repo from: https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

6. Install Terraform

#

Now, install Terraform:

yum install terraform

Again, confirm by typing 'y'. Terraform and its dependencies will be installed.

Updating Subscription Management repositories.
Hashicorp Stable - aarch64                                     437 kB/s | 108 kB     00:00
Dependencies resolved.
===============================================================================================
 Package             Arch       Version             Repository                            Size\
===============================================================================================
Installing:
 terraform           aarch64    1.7.2-1             hashicorp                             23 M
Installing dependencies:
 git                 aarch64    2.39.3-1.el9_2      rhel-9-for-aarch64-appstream-rpms     66 k
 git-core-doc        noarch     2.39.3-1.el9_2      rhel-9-for-aarch64-appstream-rpms    2.9 M
 perl-Error          noarch     1:0.17029-7.el9     rhel-9-for-aarch64-appstream-rpms     46 k
 perl-Git            noarch     2.39.3-1.el9_2      rhel-9-for-aarch64-appstream-rpms     39 k
 perl-TermReadKey    aarch64    2.38-11.el9         rhel-9-for-aarch64-appstream-rpms     40 k
 perl-lib            aarch64    0.65-480.el9        rhel-9-for-aarch64-appstream-rpms     17 k
 
Transaction Summary
===============================================================================================
Install  7 Packages
 
Total download size: 26 M
Installed size: 94 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): perl-Error-0.17029-7.el9.noarch.rpm                      20 kB/s |  46 kB     00:02
(2/7): perl-TermReadKey-2.38-11.el9.aarch64.rpm                 16 kB/s |  40 kB     00:02
(3/7): perl-lib-0.65-480.el9.aarch64.rpm                        14 kB/s |  17 kB     00:01
(4/7): git-2.39.3-1.el9_2.aarch64.rpm                           45 kB/s |  66 kB     00:01
(5/7): perl-Git-2.39.3-1.el9_2.noarch.rpm                       25 kB/s |  39 kB     00:01
(6/7): git-core-doc-2.39.3-1.el9_2.noarch.rpm                  506 kB/s | 2.9 MB     00:05
(7/7): terraform-1.7.2-1.aarch64.rpm                           1.6 MB/s |  23 MB     00:14
-----------------------------------------------------------------------------------------------
Total                                                          1.8 MB/s |  26 MB     00:14
Hashicorp Stable - aarch64                                      37 kB/s | 3.9 kB     00:00
Importing GPG key 0xA621E701:
 Userid     : "HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>"
 Fingerprint: 798A EC65 4E5C 1542 8C8E 42EE AA16 FCBC A621 E701\
 From       : https://rpm.releases.hashicorp.com/gpg\
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                       1/1
  Installing       : git-core-doc-2.39.3-1.el9_2.noarch                                    1/7
  Installing       : perl-lib-0.65-480.el9.aarch64                                         2/7
  Installing       : perl-TermReadKey-2.38-11.el9.aarch64                                  3/7
  Installing       : perl-Error-1:0.17029-7.el9.noarch                                     4/7
  Installing       : git-2.39.3-1.el9_2.aarch64                                            5/7
  Installing       : perl-Git-2.39.3-1.el9_2.noarch                                        6/7
  Installing       : terraform-1.7.2-1.aarch64                                             7/7
  Running scriptlet: terraform-1.7.2-1.aarch64                                             7/7
  Verifying        : terraform-1.7.2-1.aarch64                                             1/7
  Verifying        : perl-Error-1:0.17029-7.el9.noarch                                     2/7
  Verifying        : perl-TermReadKey-2.38-11.el9.aarch64                                  3/7
  Verifying        : perl-lib-0.65-480.el9.aarch64                                         4/7
  Verifying        : git-2.39.3-1.el9_2.aarch64                                            5/7
  Verifying        : git-core-doc-2.39.3-1.el9_2.noarch                                    6/7
  Verifying        : perl-Git-2.39.3-1.el9_2.noarch                                        7/7
Installed products updated.
 
Installed:
  git-2.39.3-1.el9_2.aarch64                      git-core-doc-2.39.3-1.el9_2.noarch
  perl-Error-1:0.17029-7.el9.noarch               perl-Git-2.39.3-1.el9_2.noarch
  perl-TermReadKey-2.38-11.el9.aarch64            perl-lib-0.65-480.el9.aarch64
  terraform-1.7.2-1.aarch64
 
Complete!

7. Verify Terraform Installation

#

Check if Terraform is installed correctly:

terraform --version

This should display the installed version of Terraform.

Terraform v1.7.2
on linux_arm64

8. Enable Terraform Autocomplete (Optional)

#

For a better command-line experience, enable the autocomplete feature:

terraform -install-autocomplete

Log out and log back in for the changes to take effect.

Hands-On Courses

#

Learn by doing with interactive courses on CopyPasteLearn:

Conclusion

#

Congratulations! You have successfully installed Terraform on RHEL 9.3. This setup paves the way for efficient infrastructure management and deployment using Terraform's powerful features. Remember to keep Terraform updated and explore its extensive documentation to make the most of your DevOps practices.

#HashiCorp#DevOps#RHEL 9.3#Terraform installation#Linux system administration

Share this article