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

fixes #572 #573

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/573.txt
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource: The `StateUpgrader` type `PriorSchema` field type has been migrated from `tfsdk.Schema` to `resource/schema.Schema`, similar to other resource schema handling
```
53 changes: 20 additions & 33 deletions internal/fwserver/server_upgraderesourcestate_test.go
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func TestServerUpgradeResourceState(t *testing.T) {
Expand Down Expand Up @@ -85,18 +84,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
0: {
PriorSchema: &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"id": {
Type: types.StringType,
PriorSchema: &schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"optional_attribute": {
Type: types.BoolType,
"optional_attribute": schema.BoolAttribute{
Optional: true,
},
"required_attribute": {
Type: types.BoolType,
"required_attribute": schema.BoolAttribute{
Required: true,
},
},
Expand Down Expand Up @@ -411,18 +407,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
0: {
PriorSchema: &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"id": {
Type: types.StringType,
PriorSchema: &schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"optional_attribute": {
Type: types.Int64Type, // Purposefully incorrect
"optional_attribute": schema.Int64Attribute{ // Purposefully incorrect
Optional: true,
},
"required_attribute": {
Type: types.Int64Type, // Purposefully incorrect
"required_attribute": schema.Int64Attribute{ // Purposefully incorrect
Required: true,
},
},
Expand Down Expand Up @@ -462,18 +455,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
0: {
PriorSchema: &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"id": {
Type: types.StringType,
PriorSchema: &schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"optional_attribute": {
Type: types.BoolType,
"optional_attribute": schema.BoolAttribute{
Optional: true,
},
"required_attribute": {
Type: types.BoolType,
"required_attribute": schema.BoolAttribute{
Required: true,
},
},
Expand Down Expand Up @@ -540,18 +530,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
0: {
PriorSchema: &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"id": {
Type: types.StringType,
PriorSchema: &schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"optional_attribute": {
Type: types.BoolType,
"optional_attribute": schema.BoolAttribute{
Optional: true,
},
"required_attribute": {
Type: types.BoolType,
"required_attribute": schema.BoolAttribute{
Required: true,
},
},
Expand Down
5 changes: 2 additions & 3 deletions resource/state_upgrader.go
Expand Up @@ -2,8 +2,7 @@ package resource

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
)

// Implementation handler for a UpgradeState operation.
Expand All @@ -19,7 +18,7 @@ type StateUpgrader struct {
//
// If not set, prior state data is available in the
// UpgradeResourceStateRequest type RawState field.
PriorSchema *tfsdk.Schema
PriorSchema *schema.Schema

// Provider defined logic for upgrading a resource state from the prior
// state version to the current schema version.
Expand Down