Skip to content

Instantly share code, notes, and snippets.

@cobusbernard
Last active July 24, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cobusbernard/4c81a98e2fa688c5132a7e28e667d87e to your computer and use it in GitHub Desktop.
Save cobusbernard/4c81a98e2fa688c5132a7e28e667d87e to your computer and use it in GitHub Desktop.
Terraform update bash script
function tf-version() {
if [ -z $1 ]; then
echo "You must specify the version!"
return
fi
echo "Switching to terraform version $1"
if [ ! -f /usr/local/Cellar/terraform/$1/terraform ]; then
echo "New version of terraform, downloading..."
curl -S https://releases.hashicorp.com/terraform/$1/terraform_$1_darwin_amd64.zip > /tmp/tf_$1.zip \
&& cd /tmp \
&& unzip /tmp/tf_$1.zip \
&& mkdir -p /usr/local/Cellar/terraform/$1/ \
&& mv terraform /usr/local/Cellar/terraform/$1/ \
&& rm /tmp/tf_$1.zip \
&& cd -
fi
rm /usr/local/bin/terraform
ln -s /usr/local/Cellar/terraform/$1/terraform /usr/local/bin/terraform
echo "Confirming version from binary:"
terraform --version
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment