terraform, aws, amazon linux 2,

How to install Terraform on Amazon Linux 2

Oct 11, 2021 · 1 min read · Post a comment

There are a lot of tutorials on how to install the latest version of Terraform out there. Most of them are pointing to the Terraform official release site, so you need to get the latest version by yourself. In this tutorial, I’m going to show you how can you install it on Amazon Linux 2 instance without referring to the official Terraform release site.

You need just to follow the installation steps and get the latest version through the Amazon Linux 2 CLI. Let’s hop in.

Prerequisites

  • Amazon Linux 2
  • sudo privileges

Install Terraform on AWS EC2 Amazon Linux 2 instance

Step 1. Instead of referring to the official Terraform release site, I’m going to create a release variable where you can always get the latest Terraform version release.

sudo release=`curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest |  grep tag_name | cut -d: -f2 | tr -d \"\,\v | awk '{$1=$1};1'`

Step 2. Now, download the package.

sudo wget https://releases.hashicorp.com/terraform/${release}/terraform_${release}_linux_amd64.zip

Step 3. To extract the file you need to have unzip installed on your instance. If not, you can run:

sudo yum install unzip

Step 4. Finally, extract the file and move the terraform binary file into /usr/local/bin where all the binaries are placed.

sudo unzip terraform_${release}_linux_amd64.zip
sudo mv terraform /usr/local/bin/

Step 5. To verify the installation and version, run:

terraform version

Output:

Terraform v1.0.8
on linux_amd64

Conclusion

This tutorial is aimed to show you the installation of the latest version of Terraform where you can accomplish all the steps through the Linux console without tromping around on the other sites. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.