terraformterraform-provider-gcp

How to install multiple or two versions of Terraform?


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?


Solution

  • 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

    Create directories to keep the Terraform binaries

    $ mkdir -p /usr/local/tf
    $ mkdir -p /usr/local/tf/11
    $ mkdir -p /usr/local/tf/12
    

    Download the binaries for both the versions

    1. Download and extract the binary for 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
      
    2. Download and extract the binary for 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
      
    3. Create symlinks for both the Terraform versions in /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*
      

    Calling different versions

    NOTE