I have a lot of Terraform modules written in Terraform 0.11 using gcp-provider of Terraform and want to upgrade the same to Terraform 0.12.
For this purpose, I need to keep both the versions installed on my system and use the version according to the version the module is written in.
I will go one by one in every module and upgrade the module using terraform 0.12upgrade
to be compatible with Terraform 0.12 as per this documentation.
How to safely keep two versions of Terraform in one System?
I'd highly recommend the tfenv tool. It sanely and easily can be used to manage multiple terraform installations. It's familiar if you've ever used nvm (for nodejs) or rvm (for ruby).
You can even add a .terraform-version
file to your modules and the tool will automatically switch terraform versions for you when you cd
into a module.
Make your life easy and install tfswitch. It takes care of installing and switching between versions you need; and it works like a magic.
I use Ubuntu 18.04 and I achieved this safely following the below steps. Similar steps can be followed to do the same on any Linux distro (making sure you are downloading the compatible binary. Confirm here)
NOTE Running the following commands as root or sudo user
$ mkdir -p /usr/local/tf
$ mkdir -p /usr/local/tf/11
$ mkdir -p /usr/local/tf/12
Terraform 0.11
in a separate directory:
$ cd /usr/local/tf/11
$ wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip
$ unzip terraform_0.11.14_linux_amd64.zip
$ rm terraform_0.11.14_linux_amd64.zip
Terraform 0.12
in a separate directory:
$ cd /usr/local/tf/12
$ wget https://releases.hashicorp.com/terraform/0.12.20/terraform_0.12.20_linux_amd64.zip
$ unzip terraform_0.12.20_linux_amd64.zip
$ rm terraform_0.12.20_linux_amd64.zip
/usr/bin/
directory:
ln -s /usr/local/tf/11/terraform /usr/bin/terraform11
ln -s /usr/local/tf/12/terraform /usr/bin/terraform12
# Make both the symlinks executable
chmod ugo+x /usr/bin/terraform*
terraform11
invokes version 0.11 and terraform12
invokes version 0.12$ terraform11
$ terraform12
NOTE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With