aws, terraform,

How to install Terraform on AWS EC2 Amazon Linux 2 instance

Oct 11, 2021 · 1 min read · Post a comment
How to install Terraform on AWS EC2 Amazon Linux 2 instance

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

  • AWS account
  • EC2 instance with Amazon Linux 2 template

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 it:

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.