Skip to content

Instantly share code, notes, and snippets.

@k3karthic
Last active May 30, 2021 15:49
Show Gist options
  • Save k3karthic/456a7532a06339e8244dc16a42e95240 to your computer and use it in GitHub Desktop.
Save k3karthic/456a7532a06339e8244dc16a42e95240 to your computer and use it in GitHub Desktop.
Update Terraform
#!/usr/bin/env bash
## Forked from https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' | # Pluck JSON value
tr -d 'v' # Remove v
}
ver=$(get_latest_release "hashicorp/terraform")
fname="terraform_$(echo $ver)_linux_amd64.zip"
echo "Fetching $ver..."
cd /tmp
curl -OL https://releases.hashicorp.com/terraform/$ver/terraform_$(echo $ver)_linux_amd64.zip
unzip $fname
mv /tmp/terraform ~/bin/
rm $fname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment