Skip to content

aws-infrastructure-code 0.11 to 0.12 TF upgrade

Archived (pre-2022)

Preserved for reference only -- likely outdated. View original | Last updated: September 2020

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.

To use it, first upgrade to Terraform v0.11.14. Then, perform the following steps:

  • terraform init to ensure your working directory is fully initialized and all required plugins are installed and selected.
  • terraform apply to ensure that your real infrastructure and Terraform state are consistent with the current configuration. The instructions produced by the checklist command assume that configuration and state are synchronized.
  • terraform 0.12checklist to see if there are any pre-upgrade steps in the checklist.

0.12checklist must be run in state directory and all modules that the state uses.

For example:
1.

$ pwd
~/fyber/aws-infrastructure-code/terraform/states/eks_cluster_1$ terraform 0.12checklist
Looks good! We did not detect any problems that ought to be
addressed before upgrading to Terraform v0.12

This tool is not perfect though, so please check the v0.12 upgrade
guide for additional guidance, and for next steps:
https://www.terraform.io/upgrade-guides/0-12.html

2.

$ pwd
~/fyber/aws-infrastructure-code/terraform/modules/spotinst_ocean_aws$ terraform 0.12checklist
Looks good! We did not detect any problems that ought to be
addressed before upgrading to Terraform v0.12

This tool is not perfect though, so please check the v0.12 upgrade
guide for additional guidance, and for next steps:
https://www.terraform.io/upgrade-guides/0-12.html

3.

$ pwd
~/fyber/aws-infrastructure-code/terraform/modules/eks_controlplane$ terraform 0.12checklist
Looks good! We did not detect any problems that ought to be
addressed before upgrading to Terraform v0.12

This tool is not perfect though, so please check the v0.12 upgrade
guide for additional guidance, and for next steps:
https://www.terraform.io/upgrade-guides/0-12.html

If all is well, the final command will produce a message like this:

Looks good! We did not detect any problems that ought to be
addressed before upgrading to Terraform v0.12

This tool is not perfect though, so please check the v0.12 upgrade
guide for additional guidance, and for next steps:
    https://www.terraform.io/upgrade-guides/0-12.html

As the message suggests, the next step in that case is to read the remainder of this page to prepare for and carry out the upgrade.

However, the checklist command may instead produce a list of one or more tasks that we recommend you perform before upgrading to Terraform 0.12, because they are easier to perform with a fully-functional Terraform 0.11 than with a Terraform 0.12 that has encountered compatibility problems.

Upgrading to Terraform 0.12

Before switching to Terraform 0.12, we recommend using Terraform v0.11.14 (or any later v0.11 release) to perform one last terraform init and terraform apply to ensure that everything is initialized and synchronized.

Once terraform apply shows no changes pending, switch over to a Terraform v0.12 release and run terraform init again to upgrade the working directory metadata to v0.12 format. (Once you've done this, you'll need to delete the .terraform directory if you wish to return to Terraform v0.11, but no real infrastructure or persisted state will be upgraded yet.)

It is possible that your configuration may be using configuration constructs that are not Terraform v0.12 compatible and thus require upgrade. In that case, terraform init will produce the following message:

Terraform has initialized, but configuration upgrades may be needed.

Terraform found syntax errors in the configuration that prevented full
initialization. If you've recently upgraded to Terraform v0.12, this may be
because your configuration uses syntax constructs that are no longer valid,
and so must be updated before full initialization is possible.

Terraform has installed the required providers to support the configuration
upgrade process. To begin upgrading your configuration, run the following:
    terraform 0.12upgrade

To see the full set of errors that led to this message, run:
    terraform validate

As mentioned in the message, Terraform has partially initialized the directory just enough to perform the configuration upgrade process, which is described in the following section.

We recommend running the configuration upgrade tool even if you do not see the above message, because it may detect and fix constructs that are syntactically correct but still need some changes to work as expected with Terraform v0.12.

Upgrading Terraform configuration

With a fully-initialized working directory (all necessary providers and child modules installed), run terraform 0.12upgrade to begin the process.

This command needs to be run first in state directory and then in all modules that this state uses.

By default it will print some information about what it is about to do and prompt for confirmation:

This command will rewrite the configuration files in the given directory so
that they use the new syntax features from Terraform v0.12, and will identify
any constructs that may need to be adjusted for correct operation with
Terraform v0.12.

We recommend using this command in a clean version control work tree, so that
you can easily see the proposed changes as a diff against the latest commit.
If you have uncommitted changes already present, we recommend aborting this
command and dealing with them before running this command again.

Would you like to upgrade the module in the current directory?

If you answer yes, the .tf and .tfvars files in your current working directory will be rewritten in-place.

Since all modules downloaded to state's directory you need to copy those into module's directory in order to upgrade module before upgrading modules:

$ pwd
~/fyber/aws-infrastructure-code/terraform/states/eks_cluster_1
$ cp -a .terraform ../../modules/eks_controlplane
$ cp -a .terraform ../../modules/spotinst_ocean_aws

After that you can perform upgrade on module(s) too.

References

More information on TF upgrade: 0 12