Last active
July 24, 2020 15:52
-
-
Save cobusbernard/4c81a98e2fa688c5132a7e28e667d87e to your computer and use it in GitHub Desktop.
Terraform update bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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