Terraform: installing Terraform manually on Ubuntu

Terraform is a popular tool for provisioning infrastructure on cloud providers such as EC2, Azure, and GCP.    If you want to install Teraform on Ubuntu using apt-get, follow HashiCorp’s standard installation document.

However, I find that I often need multiple versions for different projects.  Find your desired version of the binaries at the Terraform download page, and follow the instructions below.

sudo apt-get install jq unzip -y

# explicitly choose version OR pull latest using github api
export TERRA_VERSION=0.12.20
export TERRA_VERSION=$(curl -sL https://api.github.com/repos/hashicorp/terraform/releases/latest | jq -r ".tag_name" | cut -c2-)

# download
wget https://releases.hashicorp.com/terraform/${TERRA_VERSION}/terraform_${TERRA_VERSION}_linux_amd64.zip

# unzip
unzip terraform_${TERRA_VERSION}_linux_amd64.zip

# set permissions and move into path
chmod +x terraform
sudo mv terraform /usr/local/bin

# validate
terraform version

If you would like to manage multiple versions using update-alternatives, read my article here.

REFERENCES

terraform, install