Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save telepath/0b5208757b78e19b1fafee7ca6f1cf31 to your computer and use it in GitHub Desktop.
Save telepath/0b5208757b78e19b1fafee7ca6f1cf31 to your computer and use it in GitHub Desktop.
Install Terraform & Packer on Linux
#!/usr/bin/env bash
# from https://gist.github.com/Adron/90863e51c8c5c0ad2049890bcd8abbfb
# Script prerequisite > install jq > https://stedolan.github.io
DIR=~/bin
# Prerequisites
if [ "$(uname)" == "Darwin" ]; then
brew install jq
# For Linux
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sudo apt-get install --assume-yes jq
fi
# Get URLs for most recent versions
# For OS-X
if [ "$(uname)" == "Darwin" ]; then
terraform_url=$(curl https://releases.hashicorp.com/index.json | jq '{terraform}' | egrep "darwin.*64" | egrep -v "rc" | egrep -v "beta" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
packer_url=$(curl https://releases.hashicorp.com/index.json | jq '{packer}' | egrep "darwin.*64" | egrep -v "rc" | egrep -v "beta" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
# For Linux
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
terraform_url=$(curl https://releases.hashicorp.com/index.json | jq '{terraform}' | egrep "linux.*amd64" | egrep -v "rc" | egrep -v "beta" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
packer_url=$(curl https://releases.hashicorp.com/index.json | jq '{packer}' | egrep "linux.*amd64" | egrep -v "rc" | egrep -v "beta" | sort --version-sort -r | head -1 | awk -F[\"] '{print $4}')
fi
# Download Terraform. URI: https://www.terraform.io/downloads.html
echo "Downloading $terraform_url."
curl -o terraform.zip $terraform_url
# Unzip and install
unzip terraform.zip && rm terraform.zip
# Download Packer. URI: https://www.packer.io/downloads.html
echo "Downloading $packer_url."
curl -o packer.zip $packer_url
# Unzip and install
unzip packer.zip && rm packer.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment