Skip to content

Commit

Permalink
resource: Use schema.Schema for StateUpgrader.PriorSchema (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwarapter committed Dec 12, 2022
1 parent 8c3788a commit 3413b8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 36 deletions.
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

0 comments on commit 3413b8f

Please sign in to comment.