Upgrading Terraform command line to the latest version

Some time ago I updated my terraform command line tool to the version 0.15.3 and was surprised how easy it went. Originally I planned to write a blog but it was not too much to write about. The upgrades to version 11 or 13 were much more painful. Last week HashiCorp announced Terraform version 1.0 General Availability and it meant that the time for a new upgrade had come. I upgraded it on one of my machines and decided to write a short blog about both upgrades to encourage people to try and do the upgrade.

First, I would like to describe the previous upgrade done some time ago. The upgrade was from the 0.12.26 to 0.15.3 version and it was easy and quick. I verified my version, went to the HashiCorp Terraform site and got the link to the version 0.15.3. Then I downloaded it directly to my machine using cURL utility.

[opc@gleb-bastion-ca database-test-122]$ terraform version
Terraform v0.12.26
+ provider.oci v4.14.0
 
Your version of Terraform is out of date! The latest version
is 0.15.3. You can update by downloading from https://www.terraform.io/downloads.html
[opc@gleb-bastion-ca database-test-122]$
[opc@gleb-bastion-ca ~]$ curl -O https://releases.hashicorp.com/terraform/0.15.3/terraform_0.15.3_linux_amd64.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 31.2M  100 31.2M    0     0  6094k      0  0:00:05  0:00:05 --:--:-- 5638k
[opc@gleb-bastion-ca ~]$

Then I saved the previous version just in case and unzipped the new version to the default location.

[opc@gleb-bastion-ca ~2]$ sudo mv /usr/bin/terraform /usr/bin/terraform.12
[opc@gleb-bastion-ca ~]$ sudo unzip terraform_0.15.3_linux_amd64.zip -d /usr/bin/
Archive:  terraform_0.15.3_linux_amd64.zip
  inflating: /usr/bin/terraform
[opc@gleb-bastion-ca ~]$

And after that I needed only to run the “terraform init” command again for a new deployment. Everything worked without any problems.

[opc@gleb-bastion-ca ~]$ terraform version
Terraform v0.15.3
on linux_amd64
[opc@gleb-bastion-ca ~]$
 
 
[opc@gleb-bastion-ca ~]$ cd terraform-oci/test-oci-01/
[opc@gleb-bastion-ca test-oci-01]$ terraform init
 
Initializing the backend...
 
Initializing provider plugins...
- Finding hashicorp/oci versions matching ">= 3.27.0"...
- Finding latest version of hashicorp/null...
- Installing hashicorp/oci v4.25.0...
- Installed hashicorp/oci v4.25.0 (signed by HashiCorp)
- Installing hashicorp/null v3.1.0...
- Installed hashicorp/null v3.1.0 (signed by HashiCorp)
 
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

With the Terraform version 1.0 it was a similar experience.  Everything worked as expected and the upgrade was easy.

[opc@gleb-bastion-ca database-test-190]$ terraform -v
Terraform v0.15.3
on linux_amd64
+ provider registry.terraform.io/hashicorp/oci v4.25.0
 
Your version of Terraform is out of date! The latest version
is 1.0.0. You can update by downloading from https://www.terraform.io/downloads.html
[opc@gleb-bastion-ca database-test-190]$
 
 
[opc@gleb-bastion-ca database-test-190]$ uname -o
GNU/Linux
[opc@gleb-bastion-ca database-test-190]$
 
[opc@gleb-bastion-ca ~]$ curl -O https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 31.5M  100 31.5M    0     0  5738k      0  0:00:05  0:00:05 --:--:-- 5610k
[opc@gleb-bastion-ca ~]$ which terraform
/usr/bin/terraform
[opc@gleb-bastion-ca ~]$ sudo mv /usr/bin/terraform /usr/bin/terraform.15.3
[opc@gleb-bastion-ca ~]$ sudo unzip terraform_1.0.0_linux_amd64.zip -d /usr/bin/
Archive:  terraform_1.0.0_linux_amd64.zip
  inflating: /usr/bin/terraform
[opc@gleb-bastion-ca ~]$ terraform -v
Terraform v1.0.0
on linux_amd64
[opc@gleb-bastion-ca ~]$
 
[opc@gleb-bastion-ca database-test-190]$ terraform init
 
Initializing the backend...
 
Initializing provider plugins...
- Reusing previous version of hashicorp/oci from the dependency lock file
- Using previously-installed hashicorp/oci v4.25.0
 
Terraform has been successfully initialized!
 
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
 
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
[opc@gleb-bastion-ca database-test-190]$

When you run the “init” command after upgrade you can decide to upgrade all the modules you use for your deployment.

[opc@gleb-bastion-ca database-test-190]$ terraform init -upgrade
 
Initializing the backend...
 
Initializing provider plugins...
- Finding latest version of hashicorp/oci...
- Installing hashicorp/oci v4.30.0...
- Installed hashicorp/oci v4.30.0 (signed by HashiCorp)
 
Terraform has made some changes to the provider dependency selections recorded
in the .terraform.lock.hcl file. Review those changes and commit them to your
version control system if they represent changes you intended to make.
 
Terraform has been successfully initialized!
 
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
 
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
[opc@gleb-bastion-ca database-test-190]$

That looked great so far but what if you already had an existing running configuration created in version 15.3 for example? Terraform 1.0 is cross-compatible between versions 0.14.x, 0.15.x, and 1.0. Here is my deployment done in version 0.15.3.

[opc@gleb-bastion-ca database-test-190]$ head terraform.tfstate | grep terraform_version
  "terraform_version": "0.15.3",
[opc@gleb-bastion-ca database-test-190]$

With the terraform 1.0 I can either continue to manage it or dynamically refresh the state updating the version in the process.

[opc@gleb-bastion-ca database-test-190]$ terraform refresh
oci_core_app_catalog_listing_resource_version_agreement.generated_oci_core_app_catalog_listing_resource_version_agreement: Refreshing state... [id=2021-06-13 13:32:07.805 +0000 UTC]
...
redacted
...
vcn_id = "ocid1.vcn.oc1.ca-toronto-1.amaaaaaavrxjjqyahfoimihecy6pp5bdpmjxscrewoltl2p4jdzt3xu4vva2q"
[opc@gleb-bastion-ca database-test-190]$ head terraform.tfstate | grep terraform_version
  "terraform_version": "1.0.0",
[opc@gleb-bastion-ca database-test-190]$

I tested the Terraform 1.0 against several of my deployment and didn’t find any warnings or errors. It seemed all the code for the version 0.15.3 worked correctly in the 1.0 version.

As a conclusion I can add only that so far I haven’t encountered any issues with my current running configuration using version 1.0 but, of course, your case can be different. Happy upgrading.

Share on:
Come work with the Best