John Fox
John Fox

Reputation: 917

Error: Invalid resource instance data in state after upgrade

I've been upgrading my terraform config from 0.11 to 0.13 as well as removing a module from the state file (using terraform state rm module.mymodulename).

After removing the resource above I am now running into a whole host of errors when running a plan command. Now I'm not too sure if it's related to me removing the module or if it's linked to the upgrade. I can see that the placement_strategy attribute has been deprecated for aws_ecs_service and I'm a bit stumped on how to safely remove it from the state file.

Placement_strategy isn't something that I've defined in the resource and is just a default from the earlier version.

Anyone any advice on how to tackle the issues below? I need to get this back up and running as it's for our development environment. I'm leaning towards removing the resource "aws_ecs_service" "myappadmin-service" and importing it again.

terraform plan

Error: Invalid resource instance data in state

  on ecs-instance-role.tf line 23:
  23: resource "aws_iam_instance_profile" "ecs-instance-profile" {

Instance aws_iam_instance_profile.ecs-instance-profile data could not be
decoded from the state: unsupported attribute "roles".

Error: Invalid resource instance data in state

  on modules\myappadmin\service.tf line 1:
   1: resource "aws_ecs_service" "myappadmin-service" {

Instance module.myappadmin.aws_ecs_service.myappadmin-service data could not be
decoded from the state: unsupported attribute "placement_strategy".

Error: Invalid resource instance data in state

  on modules\myappadmin\service.tf line 1:
   1: resource "aws_ecs_service" "myappadmin-service" {

Instance module.myappadmin.aws_ecs_service.myappadmin-service data could not be
decoded from the state: unsupported attribute "placement_strategy".

Error: Invalid resource instance data in state

  on modules\myappadmin\service.tf line 1:
   1: resource "aws_ecs_service" "myappadmin-service" {

Instance module.myappadmin.aws_ecs_service.myappadmin-service data could not be
decoded from the state: unsupported attribute "placement_strategy".

Error: Invalid resource instance data in state

  on modules\myappadmin\service.tf line 1:
   1: resource "aws_ecs_service" "myappadmin-service" {

Instance module.myappadmin.aws_ecs_service.myappadmin-service data could not be
decoded from the state: unsupported attribute "placement_strategy".

Error: Invalid resource instance data in state

  on modules\myappadmin\service.tf line 1:
   1: resource "aws_ecs_service" "myappadmin-service" {

Instance module.myappadmin.aws_ecs_service.myappadmin-service data could not be
decoded from the state: unsupported attribute "placement_strategy".

Error: Invalid resource instance data in state

  on modules\myappadmin\service.tf line 1:
   1: resource "aws_ecs_service" "myappadmin-service" {

Instance module.myappadmin.aws_ecs_service.myappadmin-service data could not be
decoded from the state: unsupported attribute "placement_strategy".

Upvotes: 2

Views: 4689

Answers (1)

Martin Atkins
Martin Atkins

Reputation: 74239

I'm not sure that this fully explains what you are seeing but one of these errors seems to be related to a change to aws_ecs_service in AWS provider major version 2, which suggests that you're upgrading both Terraform and the AWS provider at the same time.

To make it easier to understand what's going on, I would suggest upgrading only one component at a time, so you can make any changes required for one upgrade before starting on the next upgrade, and so you won't have to correlate the release notes of various different components all at once.

Given what you've seen here, I would suggest the following ordering for your case:

  • Upgrade the AWS provider to the latest available release in major version 2, which is 2.70.0 at the time I'm writing this. Use the version 2 upgrade guide to try see which changes are required for any errors you encounter.
  • Then upgrade the AWS provider again to the latest available release in major version 3, which is 3.2.0 at the time I'm writing this. Use the version 3 upgrade guide to try see which changes are required for any errors you encounter.
  • Upgrade Terraform CLI to the latest v0.12 release, which is v0.12.29 at the time I'm writing this. Refer to the Terraform 0.12 upgrade guide, which describes how to use an automatic upgrade tool included in that release and also describes some less common situations that the upgrade tool can't handle automatically.
  • Finally, upgrade Terraform CLI to the latest v0.13 release. Refer to the Terraform 0.13 upgrade guide to see if you'll need to make any changes to your configuration for that upgrade. (If you only use "official" Terraform providers, like the AWS provider, then you may not need to make any changes, but could still run the automatic upgrade tool anyway to find out.)

While doing this in four steps rather than one might seem more arduous, it should mean that in each step you only need to worry about one set of release notes and you can focus any debugging you need to do on only one component.

Note that above I described upgrading one major version at a time, rather than skipping ahead. Terraform CLI in particular does not support upgrading directly from Terraform v0.11 to v0.13, because the automatic upgrade tool from Terraform v0.12 is no longer present in Terraform v0.13. The AWS provider could potentially be upgraded directly from v1 to v3, but to do that you'll need to consult the release notes of both versions at once.

It's possible that you might encounter these errors again at some point in the above process. If that is true, you'll be able to understand which change caused the problem, and potentially report the problem against that component (either the AWS provider or Terraform CLI, depending on what you've just upgraded.)

Upvotes: 3

Related Questions