@@ -16,9 +16,9 @@ import (
1616 "github.com/hashicorp/terraform-plugin-framework/tfsdk"
1717)
1818
19- // UpgradeResourceIdentityRequest is the framework server request for the
20- // UpgradeResourceIdentity RPC.
21- type UpgradeResourceIdentityRequest struct {
19+ // UpgradeIdentityRequest is the framework server request for the
20+ // UpgradeIdentity RPC.
21+ type UpgradeIdentityRequest struct {
2222 Resource resource.Resource
2323 IdentitySchema fwschema.Schema
2424 // TypeName is the type of resource that Terraform needs to upgrade the
@@ -28,10 +28,6 @@ type UpgradeResourceIdentityRequest struct {
2828 // Version is the version of the identity state the resource currently has.
2929 Version int64
3030
31- // Using the tfprotov6 type here was a pragmatic effort decision around when
32- // the framework introduced compatibility promises. This type was chosen as
33- // it was readily available and trivial to convert between tfprotov5.
34- //
3531 // Using a terraform-plugin-go type is not ideal for the framework as almost
3632 // all terraform-plugin-go types have framework abstractions, but if there
3733 // is ever a time where it makes sense to re-evaluate this decision, such as
@@ -40,15 +36,15 @@ type UpgradeResourceIdentityRequest struct {
4036 RawState * tfprotov6.RawState
4137}
4238
43- // UpgradeResourceIdentityResponse is the framework server response for the
44- // UpgradeResourceIdentity RPC.
45- type UpgradeResourceIdentityResponse struct {
39+ // UpgradeIdentityResponse is the framework server response for the
40+ // UpgradeIdentity RPC.
41+ type UpgradeIdentityResponse struct {
4642 UpgradedIdentity * tfsdk.ResourceIdentity
4743 Diagnostics diag.Diagnostics
4844}
4945
50- // UpgradeResourceIdentity implements the framework server UpgradeResourceIdentity RPC.
51- func (s * Server ) UpgradeResourceIdentity (ctx context.Context , req * UpgradeResourceIdentityRequest , resp * UpgradeResourceIdentityResponse ) {
46+ // UpgradeIdentity implements the framework server UpgradeIdentity RPC.
47+ func (s * Server ) UpgradeIdentity (ctx context.Context , req * UpgradeIdentityRequest , resp * UpgradeIdentityResponse ) {
5248 if req == nil {
5349 return
5450 }
@@ -71,11 +67,10 @@ func (s *Server) UpgradeResourceIdentity(ctx context.Context, req *UpgradeResour
7167
7268 if req .Version == req .IdentitySchema .GetVersion () {
7369 resp .Diagnostics .AddError (
74- "Unable to Read Previously Saved Identity for UpgradeResourceIdentity" ,
75- "There was an error reading the saved resource identity using the current resource identity schema.\n \n " +
76- "If this resource Identity was last refreshed with Terraform CLI 0.11 and earlier, it must be refreshed or applied with an older provider version first. " +
77- "If you manually modified the resource Identity, you will need to manually modify it to match the current resource identity schema. " +
78- "Otherwise, please report this to the provider developer:\n \n " ,
70+ "Unexpected Identity Upgrade Request" ,
71+ "Terraform Core invoked UpgradeResourceIdentity even though the stored identity schema version matches the current version. " +
72+ "This likely indicates a bug in the Terraform provider framework or Terraform Core. " +
73+ "Please report this issue to the provider developer." ,
7974 )
8075 return
8176 }
@@ -114,7 +109,7 @@ func (s *Server) UpgradeResourceIdentity(ctx context.Context, req *UpgradeResour
114109 logging .FrameworkTrace (ctx , "Resource implements ResourceWithUpgradeIdentity" )
115110
116111 logging .FrameworkTrace (ctx , "Calling provider defined Resource UpgradeIdentity" )
117- resourceIdentityUpgraders := resourceWithUpgradeIdentity .UpgradeResourceIdentity (ctx )
112+ resourceIdentityUpgraders := resourceWithUpgradeIdentity .UpgradeIdentity (ctx )
118113 logging .FrameworkTrace (ctx , "Called provider defined Resource UpgradeIdentity" )
119114
120115 // Panic prevention
@@ -134,20 +129,20 @@ func (s *Server) UpgradeResourceIdentity(ctx context.Context, req *UpgradeResour
134129 return
135130 }
136131
137- upgradeResourceIdentityRequest := resource.UpgradeResourceIdentityRequest {
138- RawState : req .RawState ,
132+ upgradeResourceIdentityRequest := resource.UpgradeIdentityRequest {
133+ RawIdentity : req .RawState ,
139134 }
140135
141136 if resourceIdentityUpgrader .PriorSchema != nil {
142- logging .FrameworkTrace (ctx , "Initializing populated UpgradeResourceIdentityRequest Identity from provider defined prior schema and request RawState" )
137+ logging .FrameworkTrace (ctx , "Initializing populated UpgradeIdentityRequest Identity from provider defined prior schema and request RawState" )
143138
144139 priorSchemaType := resourceIdentityUpgrader .PriorSchema .Type ().TerraformType (ctx )
145140
146141 rawIdentityValue , err := req .RawState .UnmarshalWithOpts (priorSchemaType , unmarshalOpts )
147142
148143 if err != nil {
149144 resp .Diagnostics .AddError (
150- "Unable to Read Previously Saved Identity for UpgradeResourceIdentity " ,
145+ "Unable to Read Previously Saved Identity for UpgradeIdentity " ,
151146 fmt .Sprintf ("There was an error reading the saved resource Identity using the prior resource schema defined for version %d upgrade.\n \n " , req .Version )+
152147 "Please report this to the provider developer:\n \n " + err .Error (),
153148 )
@@ -161,7 +156,7 @@ func (s *Server) UpgradeResourceIdentity(ctx context.Context, req *UpgradeResour
161156
162157 }
163158
164- upgradeResourceIdentityResponse := resource.UpgradeResourceIdentityResponse {
159+ upgradeResourceIdentityResponse := resource.UpgradeIdentityResponse {
165160 Identity : & tfsdk.ResourceIdentity {
166161 Schema : req .IdentitySchema ,
167162 // Raw is intentionally not set.
@@ -193,16 +188,5 @@ func (s *Server) UpgradeResourceIdentity(ctx context.Context, req *UpgradeResour
193188 return
194189 }
195190
196- if upgradeResourceIdentityResponse .Identity .Raw .Type () != nil {
197- logging .FrameworkTrace (ctx , "UpgradeResourceIdentityResponse RawState set, overriding State" )
198-
199- resp .UpgradedIdentity = & tfsdk.ResourceIdentity {
200- Schema : req .IdentitySchema ,
201- Raw : upgradeResourceIdentityResponse .Identity .Raw ,
202- }
203-
204- return
205- }
206-
207191 resp .UpgradedIdentity = upgradeResourceIdentityResponse .Identity
208192}
0 commit comments