Skip to content

Commit 3413b8f

Browse files
authored
resource: Use schema.Schema for StateUpgrader.PriorSchema (#573)
Reference: https://github.com/hashicorp/terraform-plugin-framework/issue/572
1 parent 8c3788a commit 3413b8f

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

.changelog/573.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:breaking-change
2+
resource: The `StateUpgrader` type `PriorSchema` field type has been migrated from `tfsdk.Schema` to `resource/schema.Schema`, similar to other resource schema handling
3+
```

internal/fwserver/server_upgraderesourcestate_test.go

+20-33
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/hashicorp/terraform-plugin-framework/resource"
1818
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1919
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
20-
"github.com/hashicorp/terraform-plugin-framework/types"
2120
)
2221

2322
func TestServerUpgradeResourceState(t *testing.T) {
@@ -85,18 +84,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
8584
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
8685
return map[int64]resource.StateUpgrader{
8786
0: {
88-
PriorSchema: &tfsdk.Schema{
89-
Attributes: map[string]tfsdk.Attribute{
90-
"id": {
91-
Type: types.StringType,
87+
PriorSchema: &schema.Schema{
88+
Attributes: map[string]schema.Attribute{
89+
"id": schema.StringAttribute{
9290
Computed: true,
9391
},
94-
"optional_attribute": {
95-
Type: types.BoolType,
92+
"optional_attribute": schema.BoolAttribute{
9693
Optional: true,
9794
},
98-
"required_attribute": {
99-
Type: types.BoolType,
95+
"required_attribute": schema.BoolAttribute{
10096
Required: true,
10197
},
10298
},
@@ -411,18 +407,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
411407
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
412408
return map[int64]resource.StateUpgrader{
413409
0: {
414-
PriorSchema: &tfsdk.Schema{
415-
Attributes: map[string]tfsdk.Attribute{
416-
"id": {
417-
Type: types.StringType,
410+
PriorSchema: &schema.Schema{
411+
Attributes: map[string]schema.Attribute{
412+
"id": schema.StringAttribute{
418413
Computed: true,
419414
},
420-
"optional_attribute": {
421-
Type: types.Int64Type, // Purposefully incorrect
415+
"optional_attribute": schema.Int64Attribute{ // Purposefully incorrect
422416
Optional: true,
423417
},
424-
"required_attribute": {
425-
Type: types.Int64Type, // Purposefully incorrect
418+
"required_attribute": schema.Int64Attribute{ // Purposefully incorrect
426419
Required: true,
427420
},
428421
},
@@ -462,18 +455,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
462455
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
463456
return map[int64]resource.StateUpgrader{
464457
0: {
465-
PriorSchema: &tfsdk.Schema{
466-
Attributes: map[string]tfsdk.Attribute{
467-
"id": {
468-
Type: types.StringType,
458+
PriorSchema: &schema.Schema{
459+
Attributes: map[string]schema.Attribute{
460+
"id": schema.StringAttribute{
469461
Computed: true,
470462
},
471-
"optional_attribute": {
472-
Type: types.BoolType,
463+
"optional_attribute": schema.BoolAttribute{
473464
Optional: true,
474465
},
475-
"required_attribute": {
476-
Type: types.BoolType,
466+
"required_attribute": schema.BoolAttribute{
477467
Required: true,
478468
},
479469
},
@@ -540,18 +530,15 @@ func TestServerUpgradeResourceState(t *testing.T) {
540530
UpgradeStateMethod: func(ctx context.Context) map[int64]resource.StateUpgrader {
541531
return map[int64]resource.StateUpgrader{
542532
0: {
543-
PriorSchema: &tfsdk.Schema{
544-
Attributes: map[string]tfsdk.Attribute{
545-
"id": {
546-
Type: types.StringType,
533+
PriorSchema: &schema.Schema{
534+
Attributes: map[string]schema.Attribute{
535+
"id": schema.StringAttribute{
547536
Computed: true,
548537
},
549-
"optional_attribute": {
550-
Type: types.BoolType,
538+
"optional_attribute": schema.BoolAttribute{
551539
Optional: true,
552540
},
553-
"required_attribute": {
554-
Type: types.BoolType,
541+
"required_attribute": schema.BoolAttribute{
555542
Required: true,
556543
},
557544
},

resource/state_upgrader.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package resource
22

33
import (
44
"context"
5-
6-
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
5+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
76
)
87

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

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

0 commit comments

Comments
 (0)