Skip to content

Instantly share code, notes, and snippets.

@kenske
Last active January 29, 2018 18:50
Show Gist options
  • Save kenske/efcb6444bbb2240f1eb59993ea5667ba to your computer and use it in GitHub Desktop.
Save kenske/efcb6444bbb2240f1eb59993ea5667ba to your computer and use it in GitHub Desktop.
Automatic terraform upgrade
#!/usr/bin/env bash
# Upgrade an existing terraform installation.
currentVersion=$(terraform version | head -n1 | awk '{print $2}' | cut -c 2-)
installPath=$(which terraform)
echo "Checking latest release..."
LATEST_RELEASE=$(curl -# https://api.github.com/repos/hashicorp/terraform/releases/latest | jq --raw-output '.tag_name' | cut -c 2-)
if [ "$LATEST_RELEASE" == "$currentVersion" ]; then
echo "Latest Terraform already installed."
else
echo "Upgrading to Terraform ${LATEST_RELEASE}..."
wget https://releases.hashicorp.com/terraform/${LATEST_RELEASE}/terraform_${LATEST_RELEASE}_linux_amd64.zip
unzip terraform_${LATEST_RELEASE}_linux_amd64.zip
mv terraform $installPath
rm terraform_${LATEST_RELEASE}_linux_amd64.zip
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment