Last active
January 29, 2018 18:50
-
-
Save kenske/efcb6444bbb2240f1eb59993ea5667ba to your computer and use it in GitHub Desktop.
Automatic terraform upgrade
This file contains 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
#!/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