@@ -14,6 +14,7 @@ import (
1414 "github.com/hashicorp/terraform-plugin-framework/provider"
1515 "github.com/hashicorp/terraform-plugin-framework/provider/metaschema"
1616 "github.com/hashicorp/terraform-plugin-framework/resource"
17+ "github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
1718 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
1819 "github.com/hashicorp/terraform-plugin-framework/types"
1920 "github.com/hashicorp/terraform-plugin-go/tfprotov6"
@@ -32,6 +33,12 @@ func TestServerPlanResourceChange(t *testing.T) {
3233
3334 testEmptyDynamicValue , _ := tfprotov6 .NewDynamicValue (testSchemaType , tftypes .NewValue (testSchemaType , nil ))
3435
36+ testIdentitySchemaType := tftypes.Object {
37+ AttributeTypes : map [string ]tftypes.Type {
38+ "test_id" : tftypes .String ,
39+ },
40+ }
41+
3542 testSchema := schema.Schema {
3643 Attributes : map [string ]schema.Attribute {
3744 "test_computed" : schema.StringAttribute {
@@ -43,6 +50,18 @@ func TestServerPlanResourceChange(t *testing.T) {
4350 },
4451 }
4552
53+ testIdentitySchema := identityschema.Schema {
54+ Attributes : map [string ]identityschema.Attribute {
55+ "test_id" : identityschema.StringAttribute {
56+ RequiredForImport : true ,
57+ },
58+ },
59+ }
60+
61+ type testIdentitySchemaData struct {
62+ TestID types.String `tfsdk:"test_id"`
63+ }
64+
4665 type testSchemaData struct {
4766 TestComputed types.String `tfsdk:"test_computed"`
4867 TestRequired types.String `tfsdk:"test_required"`
@@ -178,6 +197,70 @@ func TestServerPlanResourceChange(t *testing.T) {
178197 }),
179198 },
180199 },
200+ "create-request-plannedidentity" : {
201+ server : & Server {
202+ FrameworkServer : fwserver.Server {
203+ Provider : & testprovider.Provider {
204+ ResourcesMethod : func (_ context.Context ) []func () resource.Resource {
205+ return []func () resource.Resource {
206+ func () resource.Resource {
207+ return & testprovider.ResourceWithIdentityAndModifyPlan {
208+ Resource : & testprovider.Resource {
209+ SchemaMethod : func (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
210+ resp .Schema = testSchema
211+ },
212+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
213+ resp .TypeName = "test_resource"
214+ },
215+ },
216+ IdentitySchemaMethod : func (ctx context.Context , req resource.IdentitySchemaRequest , resp * resource.IdentitySchemaResponse ) {
217+ resp .IdentitySchema = testIdentitySchema
218+ },
219+ ModifyPlanMethod : func (ctx context.Context , req resource.ModifyPlanRequest , resp * resource.ModifyPlanResponse ) {
220+ var data testIdentitySchemaData
221+
222+ resp .Diagnostics .Append (req .Identity .Get (ctx , & data )... )
223+
224+ if data .TestID .ValueString () != "id-123" {
225+ resp .Diagnostics .AddError ("Unexpected req.Identity" , data .TestID .ValueString ())
226+ }
227+ },
228+ }
229+ },
230+ }
231+ },
232+ },
233+ },
234+ },
235+ request : & tfprotov6.PlanResourceChangeRequest {
236+ Config : testNewDynamicValue (t , testSchemaType , map [string ]tftypes.Value {
237+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
238+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
239+ }),
240+ ProposedNewState : testNewDynamicValue (t , testSchemaType , map [string ]tftypes.Value {
241+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
242+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
243+ }),
244+ PriorIdentity : & tfprotov6.ResourceIdentityData {
245+ IdentityData : testNewDynamicValue (t , testIdentitySchemaType , map [string ]tftypes.Value {
246+ "test_id" : tftypes .NewValue (tftypes .String , "id-123" ),
247+ }),
248+ },
249+ PriorState : & testEmptyDynamicValue ,
250+ TypeName : "test_resource" ,
251+ },
252+ expectedResponse : & tfprotov6.PlanResourceChangeResponse {
253+ PlannedState : testNewDynamicValue (t , testSchemaType , map [string ]tftypes.Value {
254+ "test_computed" : tftypes .NewValue (tftypes .String , tftypes .UnknownValue ),
255+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
256+ }),
257+ PlannedIdentity : & tfprotov6.ResourceIdentityData {
258+ IdentityData : testNewDynamicValue (t , testIdentitySchemaType , map [string ]tftypes.Value {
259+ "test_id" : tftypes .NewValue (tftypes .String , "id-123" ),
260+ }),
261+ },
262+ },
263+ },
181264 "create-request-providermeta" : {
182265 server : & Server {
183266 FrameworkServer : fwserver.Server {
@@ -344,6 +427,70 @@ func TestServerPlanResourceChange(t *testing.T) {
344427 }),
345428 },
346429 },
430+ "create-response-plannedidentity" : {
431+ server : & Server {
432+ FrameworkServer : fwserver.Server {
433+ Provider : & testprovider.Provider {
434+ ResourcesMethod : func (_ context.Context ) []func () resource.Resource {
435+ return []func () resource.Resource {
436+ func () resource.Resource {
437+ return & testprovider.ResourceWithIdentityAndModifyPlan {
438+ Resource : & testprovider.Resource {
439+ SchemaMethod : func (_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ) {
440+ resp .Schema = testSchema
441+ },
442+ MetadataMethod : func (_ context.Context , _ resource.MetadataRequest , resp * resource.MetadataResponse ) {
443+ resp .TypeName = "test_resource"
444+ },
445+ },
446+ ModifyPlanMethod : func (ctx context.Context , req resource.ModifyPlanRequest , resp * resource.ModifyPlanResponse ) {
447+ var data testIdentitySchemaData
448+
449+ resp .Diagnostics .Append (req .Identity .Get (ctx , & data )... )
450+
451+ data .TestID = types .StringValue ("new-id-123" )
452+
453+ resp .Diagnostics .Append (resp .Identity .Set (ctx , & data )... )
454+ },
455+ IdentitySchemaMethod : func (ctx context.Context , req resource.IdentitySchemaRequest , resp * resource.IdentitySchemaResponse ) {
456+ resp .IdentitySchema = testIdentitySchema
457+ },
458+ }
459+ },
460+ }
461+ },
462+ },
463+ },
464+ },
465+ request : & tfprotov6.PlanResourceChangeRequest {
466+ Config : testNewDynamicValue (t , testSchemaType , map [string ]tftypes.Value {
467+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
468+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
469+ }),
470+ ProposedNewState : testNewDynamicValue (t , testSchemaType , map [string ]tftypes.Value {
471+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
472+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
473+ }),
474+ PriorState : & testEmptyDynamicValue ,
475+ PriorIdentity : & tfprotov6.ResourceIdentityData {
476+ IdentityData : testNewDynamicValue (t , testIdentitySchemaType , map [string ]tftypes.Value {
477+ "test_id" : tftypes .NewValue (tftypes .String , "id-123" ),
478+ }),
479+ },
480+ TypeName : "test_resource" ,
481+ },
482+ expectedResponse : & tfprotov6.PlanResourceChangeResponse {
483+ PlannedState : testNewDynamicValue (t , testSchemaType , map [string ]tftypes.Value {
484+ "test_computed" : tftypes .NewValue (tftypes .String , tftypes .UnknownValue ),
485+ "test_required" : tftypes .NewValue (tftypes .String , "test-config-value" ),
486+ }),
487+ PlannedIdentity : & tfprotov6.ResourceIdentityData {
488+ IdentityData : testNewDynamicValue (t , testIdentitySchemaType , map [string ]tftypes.Value {
489+ "test_id" : tftypes .NewValue (tftypes .String , "new-id-123" ),
490+ }),
491+ },
492+ },
493+ },
347494 "create-response-requiresreplace" : {
348495 server : & Server {
349496 FrameworkServer : fwserver.Server {
0 commit comments