How to monitor any web endpoint using AWS
March 28, 2019

How to upgrade terraform to v0.12 version

terraform_Logo

Terraform

As terraform released a major version of terraform cli, providing many improvements mainly in terms of syntax, better error handling, etc, there is a need for an upgrade to this version.

Terraform has given detailed documentation on how to go to 0.12 version here.

But here is a short rundown of these steps which will help you to troubleshoot any errors or just ease you terraform cli update.

1. Check your existing terraform version

terraform -v

2. Upgrade to Terraform 0.11 first
If your current version is not 0.11 then upgrade it to 0.11.14 first. If you are on 0.11.x, please make sure you are on 0.11.14.
Every major version upgrade steps are given here.
3. Pre-upgrade Checklist
Terraform v0.11.14 introduced a temporary helper command terraform 0.12checklist, which analyzes your configuration to detect any required steps that will be easier to perform before upgrading.

4. Initialization

terraform init

5. Then plan, make sure no errors are shown

terraform plan

6. Apply – to ensure that your real infrastructure and Terraform state are consistent with the current configuration.

terraform apply

7. Do the checklist check to see if there are any pre-upgrade steps in the checklist

terraform 0.12checklist

8. Resolve suggestions from checklist – Depending upon the suggestions above, take the steps & change the tf scripts. For me, it was upgrading the aws provider version, which was shown in the output above. If you are using templates, then you need to update the template provider as well. Run above command until there are no suggestions.
Example of change is:


provider "aws" {
  region  = "eu-central-1"
  version = "~> 2.12.0"
}

9. Download and Upgrade to terraform 0.12
For Mac:

brew upgrade terraform

Others, just download the archive and follow the steps as per the OS. Download is available here.
10. Initialization

terraform init

11. Check for errors

terraform validate

12. Auto update the code with below command. Terraform v0.12 includes a new command terraform 0.12upgrade that will read the configuration files for a module written for Terraform 0.11 and update them in-place to use the cleaner Terraform 0.12 syntax and also adjust for use of features that have changed behavior in the 0.12 Terraform language.

terraform 0.12upgrade

13. Final steps


terraform plan
terraform apply

The last command ‘apply’ should run without any errors and that’s all. You terraform is upgraded to the latest major release.

Bitnami