Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State migration for old attribute "body" is missing. #165

Closed
1 task done
pascal-hofmann opened this issue Jul 27, 2022 · 8 comments
Closed
1 task done

State migration for old attribute "body" is missing. #165

pascal-hofmann opened this issue Jul 27, 2022 · 8 comments
Labels

Comments

@pascal-hofmann
Copy link

Terraform CLI and Provider Versions

terraform 1.2.5
provider 3.0.0

Terraform Configuration

irrelevant

Expected Behavior

Proper migration of old state.

Actual Behavior

… could not be decoded from the state: unsupported attribute "body". :(

Steps to Reproduce

Create state with old module, update to new module and try to apply again.

How much impact is this issue causing?

High

Logs

No response

Additional Information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@pascal-hofmann
Copy link
Author

See #140 / #142

@pascal-hofmann
Copy link
Author

I'm looking into this. Will try to create a PR today.

@bendbennett
Copy link
Contributor

bendbennett commented Jul 27, 2022

Hi @pascal-hofmann sorry you ran into trouble here.

Could you possibly post a complete example of the terraform code you are using along with the version of the http provider that you are/were using prior to upgrading to v3.0.0?

Are you trying to use the body attribute somewhere in your configuration?
Reason I ask is that the body attribute has been removed in v3.0.0 and replaced by response_body so I'm wondering if this is part of the issue?

@pascal-hofmann
Copy link
Author

This is the issue. data resources are also persisted to state. When the schema changes, a state upgrader is required. I'm currently working on a PR. I'm just getting used to the new framework instead of sdk.

@pascal-hofmann
Copy link
Author

pascal-hofmann commented Jul 27, 2022

@bendbennett I think currently the framework does not support state upgraders for data sources. :(

@bflad Do you have an idea, how to handle this case?

In the meantime I think I'll pin the provider version to 2. (I don't want to fix the state manually, because we have a lot of these data sources in a lot of states.)

@pascal-hofmann
Copy link
Author

pascal-hofmann commented Jul 27, 2022

I was able to create a minimal test case for this.

It only happens if the deprecated body attribute has still been used in the last apply with terraform-provider-http 2.x.

If you then upgrade to 3.0.0, it will fail with:

╷
│ Error: Unsupported attribute
│
│   on main.tf line 15, in resource "local_file" "this":
│   15:   content  = data.http.this.body
│
│ This object has no argument, nested block, or exported attribute named "body".

Workaround: Switch to using response_body prior to upgrading to terraform-provider-http 3.

Test case:

terraform {
  required_providers {
    http = {
      source  = "hashicorp/http"
      version = "<3" # comment after first apply, run terrform init -upgrade, change body to response_body and apply again
    }
  }
}

data "http" "this" {
  url = "https://www.hashicorp.com"
}

resource "local_file" "this" {
  content  = data.http.this.body
  filename = "${path.module}/hashicorp.com.html"
}

I'll close this issue.

@bflad
Copy link
Member

bflad commented Jul 27, 2022

This feels like a redux of this recent core issue hashicorp/terraform#30823 and pull request hashicorp/terraform#30830 -- it seems valuable to raise an issue upstream to see if Terraform core can actually ignore data source prior state in this situation, if its being consulted for plan generation.

@bflad
Copy link
Member

bflad commented Jul 27, 2022

By the way, there is no concept of state upgrades for data sources. There is only the UpgradeResourceState RPC that is used with managed resources. The prior data source state is only supposed to be "informative" for plan generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants