Created
March 30, 2020 09:49
-
-
Save vad/d326a3291f872f58efad73814d71c534 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -u | |
LATEST_RELEASE=$(curl https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-) | |
CURRENT_RELEASE=$(terraform version | grep -oP 'Terraform v\K[\d\.]+') | |
if [ "${LATEST_RELEASE}" == "${CURRENT_RELEASE}" ]; then | |
echo "Latest Terraform already installed." | |
exit 0 | |
fi | |
echo "Installing Terraform ${LATEST_RELEASE}..." | |
TMPDIR=$(mktemp -d --suffix=.tf-update) | |
cd $TMPDIR | |
curl --output terraform.zip https://releases.hashicorp.com/terraform/${LATEST_RELEASE}/terraform_${LATEST_RELEASE}_linux_amd64.zip | |
unzip terraform.zip | |
sudo mv terraform /usr/local/bin/ | |
rm -rf $TMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment