Skip to content

Instantly share code, notes, and snippets.

@cinco
Forked from danisla/terraform-install.sh
Last active January 26, 2020 18:57
Show Gist options
  • Save cinco/70adaf59c61e92dfeafcb512cd987960 to your computer and use it in GitHub Desktop.
Save cinco/70adaf59c61e92dfeafcb512cd987960 to your computer and use it in GitHub Desktop.
Terraform latest version install script (modified to zsh and exclude alpha versions)
#!/bin/bash
function terraform-install() {
[[ -f ${HOME}/bin/terraform ]] && echo "`${HOME}/bin/terraform version` already installed at ${HOME}/bin/terraform" && return 0
LATEST_URL=$(curl -sL https://releases.hashicorp.com/terraform/index.json | jq -r '.versions[].builds[].url' | egrep 'terraform_[0-9]\.[0-9]{1,2}\.[0-9]{1,2}_linux.*amd64' | sort -V | tail -1)
curl ${LATEST_URL} > /tmp/terraform.zip
mkdir -p ${HOME}/bin
(cd ${HOME}/bin && unzip /tmp/terraform.zip)
if [[ -z $(grep 'export PATH=${HOME}/bin:${PATH}' ~/.bashrc) ]]; then
echo 'export PATH=${HOME}/bin:${PATH}' >> ~/.zshrc
fi
echo "Installed: `${HOME}/bin/terraform version`"
cat - << EOF
Run the following to reload your PATH with terraform:
source ~/.zshrc
EOF
}
terraform-install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment