Skip to content

Installing Hashicorp Terraform

These notes were sourced from het_tanis' Killercoda lab and the Hashicorp Terraform documentation.

Table of Contents

Terraform Installation

Debian-based Install

Setup the hashicorp repositories (Debian-based)


Install dependencies:

  • gnupg
  • software-properties-common
  • curl
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common

Install the HashiCorp GPG key:

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

Verify the key's fingerprint:

gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint

The gpg command will report the key fingerprint:

/usr/share/keyrings/hashicorp-archive-keyring.gpg
-------------------------------------------------
pub   rsa4096 XXXX-XX-XX [SC]
AAAA AAAA AAAA AAAA
uid           [ unknown] HashiCorp Security (HashiCorp Package Signing) <security+packaging@hashicorp.com>
sub   rsa4096 XXXX-XX-XX [E]


Add the official HashiCorp repository to your system.

Add the official HashiCorp repository to your system:

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

Install Terraform from the Hashicorp Repository

Download the package information from HashiCorp.

sudo apt update

Install Terraform from the new repository.

sudo apt-get install terraform


Do some basic checks to see that it is correctly setup.

  1. Check where the system installed Terraform.
  2. Check Terraform functionality.

  3. Check where the system put Terraform binary.

    which terraform
    

  4. Verify Terraform functionality.

    terraform -help
    
    Make sure you look at some of the capabilities you have with Terraform.

  5. Check Terraform subcommands

    terraform -help plan
    

RHEL-based install

Using Yum

Install dependencies:

sudo yum install -y yum-utils

Add the yum repository:

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

Install terraform:

sudo yum -y install terraform

Using DNF

curl https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo | sudo tee /etc/yum.repos.d/hashicorp.repo

tl;dr:

Debian

# make sure gpg is present
sudo apt update && sudo apt install gpg

# add repository gpg key
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

# verify key's fingerprint
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint

# add hashicorp repo
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(grep -oP '(?<=UBUNTU_CODENAME=).*' /etc/os-release | lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

Resources