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: Initial ResourceWithUpgradeState implementation #292

Merged
merged 6 commits into from
Apr 21, 2022

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Apr 18, 2022

Closes #42
Reference: #228

Support provider defined UpgradeResourceState RPC handling, by introducing an optional ResourceWithUpgradeState interface type, with an UpgradeState method. Each underlying state version upgrade implementation is expected to consume the prior state, perform any necessary data manipulations, then respond with the upgraded state.

This framework implementation differs from the terraform-plugin-sdk implementation:

  • State upgraders are specified via a mapping, rather than a slice with underlying version field. This should prevent certain classes of coding issues.
  • State upgraders must be wholly contained from the prior state version to the current schema version. The framework does not loop through each successive version because attempting to recreate the tfprotov6.RawState for each intermediate version request would be very problematic. For example, terraform-plugin-go does not implement functionality for marshalling a RawState. Provider developers can use their own coding techniques to reduce code duplications when multiple versions need the same logic.
  • Specifying the full prior schema is now an optional implementation detail. Working with the lower level data types is more challenging, however this has been a repeated feature request.

There are some quirks and potential future enhancements to the framework UpgradeResourceState handling:

  • Past and current versions Terraform CLI will call UpgradeResourceState even if the state version matches the current schema version. This implementation keeps the framework's prior logic to roundtrip the existing state into the upgraded state. It may be possible to stop this Terraform CLI behavior with protocol version 6, although the logic would need to remain for backwards compatibility.
  • It may be possible to help provider developers simplify logic by attempting to automatically populate compatible parts of the upgraded state from the prior state. This can potentially be done at a later time.

@bflad bflad added enhancement New feature or request sdkv2-parity Issues tracking feature parity with terraform-plugin-sdk v2 and PRs working towards it. labels Apr 18, 2022
@bflad bflad added this to the v0.7.0 milestone Apr 18, 2022
bflad added a commit that referenced this pull request Apr 18, 2022
bflad added 3 commits April 19, 2022 10:14
Reference: #42
Reference: #228

Support provider defined `UpgradeResourceState` RPC handling, by introducing an optional `ResourceWithUpgradeState` interface type, with an `UpgradeState` method. Each underlying state version upgrade implementation is expected to consume the prior state, perform any necessary data manipulations, then respond with the upgraded state.

This framework implementation differs from the terraform-plugin-sdk implementation:

- State upgraders are specified via a mapping, rather than a slice with underlying version field. This should prevent certain classes of coding issues.
- State upgraders must be wholly contained from the prior state version to the current schema version. The framework does not loop through each successive version because attempting to recreate the `tfprotov6.RawState` for each intermediate version request would be very problematic. For example, terraform-plugin-go does not implement functionality for marshalling a `RawState`. Provider developers can use their own coding techniques to reduce code duplications when multiple versions need the same logic.
- Specifying the full prior schema is now an optional implementation detail. Working with the lower level data types is more challenging, however this has been a repeated feature request.

There are some quirks and potential future enhancements to the framework `UpgradeResourceState` handling:

- Past and current versions Terraform CLI will call `UpgradeResourceState` even if the state version matches the current schema version. This implementation keeps the framework's prior logic to roundtrip the existing state into the upgraded state. It may be possible to stop this Terraform CLI behavior with protocol version 6, although the logic would need to remain for backwards compatibility.
- It may be possible to help provider developers simplify logic by attempting to automatically populate compatible parts of the upgraded state from the prior state. This can potentially be done at a later time.
@bflad bflad force-pushed the bflad-UpgradeResourceState branch from 8121366 to 58c7313 Compare April 19, 2022 14:16
@bflad bflad marked this pull request as ready for review April 20, 2022 19:27
@bflad bflad requested a review from a team as a code owner April 20, 2022 19:27
@bflad
Copy link
Contributor Author

bflad commented Apr 21, 2022

Associated terraform.io update: hashicorp/terraform-website#2255

@bflad bflad merged commit 04be243 into main Apr 21, 2022
@bflad bflad deleted the bflad-UpgradeResourceState branch April 21, 2022 19:51
thiskevinwang pushed a commit to hashicorp/terraform-docs-common that referenced this pull request Apr 29, 2022
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 May 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request sdkv2-parity Issues tracking feature parity with terraform-plugin-sdk v2 and PRs working towards it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support upgrading resource state
2 participants