Terraform 0.12

So Terraform 0.12 was just released. I sat down this morning to have a quick play with it. I strongly recommend following the upgrade guide and make a separate branch of your TF files before testing 0.12.

After getting everything setup and ready to test I ran a plan and apply using Terraform 0.11.14 and got my infrastructure to a state where no further changes were required. I then ran terraform.exe 0.12checklist and I was presented with the below message:

.\terraform 0.12checklist
After analyzing this configuration and working directory, we have identified some necessary steps that we recommend you take before upgrading to Terraform v0.12:

  • [ ] The variable name “count” is now reserved. Terraform 0.12 reserves certain variable names that have (or will have in future) a special meaning when used in a “module” block. The name of this variable must be changed before upgrading to v0.12. This will unfortunately be a breaking change for any user of this module, requiring a major release to indicate that.
    For more information on the reserved variable names, see the documentation at https://www.terraform.io/docs/configuration/variables.html .

Taking these steps before upgrading to Terraform v0.12 will simplify the upgrade process by avoiding syntax errors and other compatibility problems.

So yeah, I had a variable called count which I used to control how many VMs I was creating in one go. This was a fairly easy fix as I just needed to call the variable something else, in my case I renamed the variable to ‘vmcount’ and updated the relevant stanzas in the TF files. Then running terraform.exe 0.12checklist yielded:

.\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

Finally I ran terraform.exe 0.12upgrade:

.\terraform.exe 0.12upgrade

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 uncommited 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?
Only ‘yes’ will be accepted to confirm.

Enter a value: yes

This modified my TF files, most notably removing the old interpolation syntax. Here’s a before and after example:

Before:

resource “azurerm_virtual_network” “hub” { name = “${var.hubvnetname}” address_space = “${var.hubaddressspace}” location = “${azurerm_resource_group.networkrg.location}” resource_group_name = “${azurerm_resource_group.networkrg.name}” tags = “${azurerm_resource_group.networkrg.tags}”}

After:

resource “azurerm_virtual_network” “hub” {
name = var.hubvnetname
address_space = var.hubaddressspace
location = azurerm_resource_group.networkrg.location
resource_group_name = azurerm_resource_group.networkrg.name
tags = azurerm_resource_group.networkrg.tags
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s