Created
December 27, 2018 13:31
-
-
Save GuilhermeBarile/a6711d20b82695050377987020aaee58 to your computer and use it in GitHub Desktop.
Update terraform to latest release
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
#!/bin/bash | |
current_version=$(terraform -v | head -n1 | cut -dv -f2) | |
echo "Running terraform $current_version" | |
echo -n "Checking for updates..." | |
version=$(curl -s https://releases.hashicorp.com/terraform/ | grep -vE '(alpha|beta|rc)' | grep 'href="/terraform' | cut -d\" -f2 | head -n1 | cut -d\/ -f3) | |
if [ "$version" = "$current_version" ]; then | |
echo "Already updated" | |
exit; | |
else | |
echo "New release $version" | |
fi | |
url=https://releases.hashicorp.com/terraform/${version}/terraform_${version}_linux_amd64.zip | |
TMPFILE=`mktemp` | |
dest=~/bin | |
curl -L "$url" -o $TMPFILE | |
unzip -d $dest $TMPFILE | |
rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment