Installing Hashicorp Terraform¶
Terraform Installation¶
Terraform can be installed via package manager on most Linux distros.
The Hashicorp repository must be added to install via package manager.
Debian-based Install¶
Quick setup¶
wget -O - https://apt.releases.hashicorp.com/gpg |
sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) 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
The repository can alternatively be added by using apt-key add and apt-add-repository:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt update
sudo apt install terraform
Setup the hashicorp repositories (Debian-based)¶
- Also see the official installation guide
Add the apt repository by downloading the GPG key, adding it to the keyring, then adding the appropriate repo.
Install dependencies¶
gnupgsoftware-properties-commoncurl/wget
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.
Install Terraform from the new repository.
Do some basic checks to see that it is correctly setup.¶
- Check where the system installed Terraform.
-
Check Terraform functionality.
-
Check where the system put Terraform binary.
-
Verify Terraform functionality.
Make sure you look at some of the capabilities you have with Terraform. -
Check Terraform subcommands
RedHat-based Install¶
Using Yum¶
Install dependencies:
Add the yum repository:
Install terraform:
Using DNF¶
curl https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo |
sudo tee /etc/yum.repos.d/hashicorp.repo
sudo dnf install -y terraform
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