Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Last active June 19, 2021 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeruiz/fd4c3a1225a415764cbbcd4e747617c8 to your computer and use it in GitHub Desktop.
Save rogeruiz/fd4c3a1225a415764cbbcd4e747617c8 to your computer and use it in GitHub Desktop.
A simple way to track Terraform versions using only Bash
chooseTerraform() {
# Choose a specific version of terraform based on binaries being in your path
# with a `-` separator e.g. $PATH/terraform-v0.11.14, $PATH/terraform-v0.12.1
select version in $(ls /usr/local/bin/ | grep terraform\- | cut -d '-' -f 2)
do
if [[ $version == "" ]]
then
echo "Please choose from the available versions!"
continue
fi
file="/usr/local/bin/terraform-${version}"
# Check if there's already a symlink in place and delete it.
rm -rf $(find /usr/local/bin -type l -name terraform)
ln -s /usr/local/bin/terraform-${version} /usr/local/bin/terraform
break
done
}
alias wtf=chooseTerraform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment