Skip to content

Instantly share code, notes, and snippets.

@KrustyHack
Forked from josh-padnick/get-latest-terraform.sh
Last active January 21, 2020 10:44
Show Gist options
  • Save KrustyHack/065b6c8ab2bf830edaeef6da68beaedd to your computer and use it in GitHub Desktop.
Save KrustyHack/065b6c8ab2bf830edaeef6da68beaedd to your computer and use it in GitHub Desktop.
Get latest Terraform release Linux amd64
#!/bin/bash
#
# Download latest Terraform release and install it in ~/.bin/
#
TMP_DIR=/tmp/terraform
BIN_DIR=~/.bin
LATEST_RELEASE=$(curl -Ss https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)
echo "Installing Terraform ${LATEST_RELEASE}..."
rm -rf ${TMP_DIR}
mkdir -p ${TMP_DIR}
wget --quiet "https://releases.hashicorp.com/terraform/${LATEST_RELEASE}/terraform_${LATEST_RELEASE}_linux_amd64.zip" -O ${TMP_DIR}/terraform.zip
unzip "${TMP_DIR}/terraform.zip" -d ${TMP_DIR}
mv "${TMP_DIR}/terraform" "${BIN_DIR}/terraform"
touch "${HOME}/.terraform.d/${LATEST_RELEASE}"
rm -rf ${TMP_DIR}
terraform version
echo "Installation finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment