Last active
June 19, 2021 01:58
-
-
Save rogeruiz/fd4c3a1225a415764cbbcd4e747617c8 to your computer and use it in GitHub Desktop.
A simple way to track Terraform versions using only Bash
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
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