From 6fec238ce7ffb62590b1ac8944de0dd03478522a Mon Sep 17 00:00:00 2001 From: Iain Adams Date: Fri, 9 Dec 2022 21:01:20 +0000 Subject: [PATCH 1/2] fixes #572 --- .../server_upgraderesourcestate_test.go | 53 +++++++------------ resource/state_upgrader.go | 5 +- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/internal/fwserver/server_upgraderesourcestate_test.go b/internal/fwserver/server_upgraderesourcestate_test.go index b967e9fac..a22e3c27b 100644 --- a/internal/fwserver/server_upgraderesourcestate_test.go +++ b/internal/fwserver/server_upgraderesourcestate_test.go @@ -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) { @@ -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, }, }, @@ -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, }, }, @@ -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, }, }, @@ -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, }, }, diff --git a/resource/state_upgrader.go b/resource/state_upgrader.go index f3854de65..3b724581e 100644 --- a/resource/state_upgrader.go +++ b/resource/state_upgrader.go @@ -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. @@ -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. From eeacccbc22d95df63c6bdf7f62c4d40fdf6f2afc Mon Sep 17 00:00:00 2001 From: Iain Adams Date: Sun, 11 Dec 2022 12:56:40 +0000 Subject: [PATCH 2/2] add changelog for StateUpgrader PriorSchema breaking change --- .changelog/573.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/573.txt diff --git a/.changelog/573.txt b/.changelog/573.txt new file mode 100644 index 000000000..cde5e90c8 --- /dev/null +++ b/.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 +```