Skip to content

Instantly share code, notes, and snippets.

@GuilhermeBarile
Created December 27, 2018 13:31
Show Gist options
  • Save GuilhermeBarile/a6711d20b82695050377987020aaee58 to your computer and use it in GitHub Desktop.
Save GuilhermeBarile/a6711d20b82695050377987020aaee58 to your computer and use it in GitHub Desktop.
Update terraform to latest release
#!/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