Terraform 0.11->0.12 migration: stabs at the state file

October 30, 2020 

We maintain a rather complex AWS environment built with Terraform that uses nested modules and lots of per-resource provider configurations. Recently the pain of staying with Terraform 0.11 became too much, so we had to start the migration to Terraform 0.12, with 0.13 going to follow soon after. In general the official upgrade instructions were pretty good. Of course there was a lot of manual fixing that had to be done, and as I did not keep detailed notes I can't recall all the steps I went through. But I think all or most of those can be found from other sources.

Two issue are probably worth mentioning, as they required manually poking at the state file:

-                    "provider": "module.my_env.module.my_instance_example_org.provider.aws.${var.region}"
+                    "provider": "module.my_env.module.my_instance_example_org.provider.aws"


-                "aws_sns_topic_subscription.507225ec-13f2-4f17-ab61-b3267d15dca9": {
+                "aws_sns_topic_subscription.my_topic": {

The first case shows how Terraform 0.11 state file can unintentionally contain variable interpolations, which Terraform 0.12 chokes on.

The second is an example of an issue with resource name starting with a number - it was ok with 0.11, but not with 0.12.

The only way to fix these was to download the state file directly from the backend, fix all these issues and copy the fixed version back. After that Terraform 0.12 was a happy camper.

Samuli Seppänen
Samuli Seppänen
Author archive
menucross-circle