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

tfsdk: Send UpgradeResourceStateResponse.UpgradedState.Msgpack for Terraform 0.12-0.14 Compatibility #262

Closed
bflad opened this issue Feb 15, 2022 · 3 comments · Fixed by #263
Assignees
Labels
bug Something isn't working
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Feb 15, 2022

Module version

v0.5.0

Relevant provider source code

hashicorp/terraform-provider-corner#44

Expected Behavior

While the framework has not actually implemented UpgradeResourceState handling (refer to #42), there is currently a passthrough implementation there since the RPC is always invoked. When passing a framework provider through terraform-plugin-mux tf6to5server for Terraform CLI 0.12+ compatibility, there should be no errors either.

Actual Behavior

Terraform CLI 0.12 through 0.14 return the following (less than helpful) error:

Error: EOF

This is because those versions of Terraform CLI requires the Msgpack field to be populated. This will require converting from RawState JSON and flatmap to MessagePack.

Steps to Reproduce

Using any framework provider and tf6to5server:

  1. terraform apply
  2. terraform apply

Using hashicorp/terraform-provider-corner#44:

  1. go test ./internal/tf6to5provider

References

@bflad bflad added the bug Something isn't working label Feb 15, 2022
@bflad bflad added this to the v0.6.0 milestone Feb 15, 2022
@bflad
Copy link
Contributor Author

bflad commented Feb 15, 2022

Another option here would be to have tf6to5server automatically handle this situation (likely in both directions), so the newer framework code can remain clean. I'll also open and link an issue in terraform-plugin-mux.

@bflad
Copy link
Contributor Author

bflad commented Feb 16, 2022

Upon further consideration, this functionality should be implemented in this framework, rather than terraform-plugin-mux, whose implementations should be kept as straightforward routing or 1:1 translations.

bflad added a commit that referenced this issue Feb 17, 2022
…pgradeResourceState RPC

Reference: #42
Reference: #262
Reference: hashicorp/terraform-provider-corner#44

Terraform CLI version 0.12 through 0.14 support protocol version 5 and require the `UpgradeResourceStateResponse` type `UpgradedState` type `Msgpack` field. To support downgraded framework providers via terraform-plugin-mux `tf6to5server`, the `RawState` type `JSON` field cannot simply be passed through like the previous implementation. This change will parse the `RawState` and output it via the `tfprotov6.NewDynamicValue()` function, which will always set the `Msgpack` field.

Similar logic would have already been required as part of the larger effort to support resource versioning and upgrading resource state over time.

Passthrough of the same state of an invalid resource type should not have been previously allowed, since the provider did not implement the resource type. Regardless, Terraform CLI should not have reached this point since `GetProviderSchema` would not have returned the resource type anyways for other resource operations.

Verified via integration testing of terraform-plugin-mux `tf6to5server`, which previously returned a non-descript `EOF` error.
bflad added a commit that referenced this issue Feb 22, 2022
…pgradeResourceState RPC (#263)

Reference: #42
Reference: #262
Reference: hashicorp/terraform-provider-corner#44

Terraform CLI version 0.12 through 0.14 support protocol version 5 and require the `UpgradeResourceStateResponse` type `UpgradedState` type `Msgpack` field. To support downgraded framework providers via terraform-plugin-mux `tf6to5server`, the `RawState` type `JSON` field cannot simply be passed through like the previous implementation. This change will parse the `RawState` and output it via the `tfprotov6.NewDynamicValue()` function, which will always set the `Msgpack` field.

Similar logic would have already been required as part of the larger effort to support resource versioning and upgrading resource state over time.

Passthrough of the same state of an invalid resource type should not have been previously allowed, since the provider did not implement the resource type. Regardless, Terraform CLI should not have reached this point since `GetProviderSchema` would not have returned the resource type anyways for other resource operations.

Verified via integration testing of terraform-plugin-mux `tf6to5server`, which previously returned a non-descript `EOF` error.
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
1 participant