Skip to content

Instantly share code, notes, and snippets.

@kshcherban
Last active April 23, 2020 19:14
Show Gist options
  • Save kshcherban/c3b21e9c7caab4aeb3308bf1d267d5e1 to your computer and use it in GitHub Desktop.
Save kshcherban/c3b21e9c7caab4aeb3308bf1d267d5e1 to your computer and use it in GitHub Desktop.
Bash script to auto update terraform on linux
#!/bin/bash
INSTALL_DIR="${1:-/opt/terraform}"
URL="https://releases.hashicorp.com/terraform"
VER="$(curl -sL $URL | grep -v beta | grep -Po "_(\d*\.?){3}" | sed 's/_//' | sort -V | tail -1)"
ZIP="terraform_${VER}_linux_amd64.zip"
echo "* Downloading ${URL}/${VER}/terraform_${VER}_linux_amd64.zip"
curl -s ${URL}/${VER}/terraform_${VER}_linux_amd64.zip -o ${INSTALL_DIR}/${ZIP}
echo "* Extracting $ZIP into $INSTALL_DIR"
unzip -o ${INSTALL_DIR}/$ZIP -d $INSTALL_DIR && rm -v ${INSTALL_DIR}/$ZIP
@cbitter78
Copy link

My mac's version of sort did not have -V so I used this.
curl -sL "https://releases.hashicorp.com/terraform" | grep -v beta | grep -v rc1 | grep '<a href="'.*terraform | cut -d'/' -f3 | sort -n | head -n 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment