Skip to content

Instantly share code, notes, and snippets.

@wagnst
Last active May 5, 2020 12:14
Show Gist options
  • Save wagnst/64640827eb54ed1bb7334a216c5c1ce7 to your computer and use it in GitHub Desktop.
Save wagnst/64640827eb54ed1bb7334a216c5c1ce7 to your computer and use it in GitHub Desktop.
Switch terraform version via bash
#Terraform version switch
function terraformv() {
if [ $# -eq 1 ]; then
if test -f "/opt/terraform/terraform-${1}"; then
sudo rm /opt/terraform/terraform
sudo ln -s "/opt/terraform/terraform-${1}" /opt/terraform/terraform
echo "switched to terraform-${1}"
else
echo "terraform-${1} does not exist, pls download from https://releases.hashicorp.com/terraform/ first and store in /opt/terraform."
return 1
fi
fi
}
alias tfv='terraformv'
@wagnst
Copy link
Author

wagnst commented May 5, 2020

Usage example:

$ tfv 0.12.24
terraform-0.12.24 does not exist, pls download from https://releases.hashicorp.com/terraform/ first and store in /opt/terraform.

or

$ tfv 0.12.21
switched to terraform-0.12.21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment