Skip to content

Instantly share code, notes, and snippets.

@luisc009
Created May 27, 2019 22:04
Show Gist options
  • Save luisc009/de6e3af00de1f93e64bb7d855a06b126 to your computer and use it in GitHub Desktop.
Save luisc009/de6e3af00de1f93e64bb7d855a06b126 to your computer and use it in GitHub Desktop.
Downloads Terraform 12 and 11.14 and creates a function to switch between them.
OS=$(uname | awk '{ print tolower($0)}')
#Download Terraform 12
curl -s -o terraform12.zip https://releases.hashicorp.com/terraform/0.12.0/terraform_0.12.0_${OS}_amd64.zip
#Download Terraform 11.14
curl -s -o terraform11.14.zip https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_${OS}_amd64.zip
mkdir -p $HOME/.bin/terraform/11.14/ $HOME/.bin/terraform/12/
unzip terraform12.zip -d $HOME/.bin/terraform/12
unzip terraform11.14.zip -d $HOME/.bin/terraform/11.14
echo "
#Terraform
TERRAFORM_VERSION=\${TERRAFORM_VERSION-"11.14"}
set_terraform() {
ln -s -f \$HOME/.bin/terraform/\${TERRAFORM_VERSION}/terraform /usr/local/bin/terraform
terraform -v
}
" >> $HOME/.bash_profile
@luisc009
Copy link
Author

To switch between version just export or declare TERRAFORM_VERSION=${VERSION} before executing the set_terraform function.

$TERRAFORM_VERSION=12 set_terraform 
Terraform v0.12.0
$ set_terraform 
Terraform v0.11.14

Your version of Terraform is out of date! The latest version
is 0.12.0. You can update by downloading from www.terraform.io/downloads.html

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