@@ -580,6 +580,106 @@ func TestServerCreateResource(t *testing.T) {
580580 Private : testEmptyPrivate ,
581581 },
582582 },
583+ "response-invalid-nil-identity" : {
584+ server : & fwserver.Server {
585+ Provider : & testprovider.Provider {},
586+ },
587+ request : & fwserver.CreateResourceRequest {
588+ PlannedState : & tfsdk.Plan {
589+ Raw : tftypes .NewValue (testSchemaType , map [string ]tftypes.Value {
590+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
591+ "test_required" : tftypes .NewValue (tftypes .String , "test-plannedstate-value" ),
592+ }),
593+ Schema : testSchema ,
594+ },
595+ IdentitySchema : testIdentitySchema ,
596+ ResourceSchema : testSchema ,
597+ Resource : & testprovider.ResourceWithIdentity {
598+ Resource : & testprovider.Resource {
599+ CreateMethod : func (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
600+ resp .Identity .Raw = tftypes .NewValue (testIdentitySchema .Type ().TerraformType (ctx ), nil )
601+ // Prevent missing resource state error diagnostic
602+ var data testSchemaData
603+
604+ resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
605+ resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
606+ },
607+ },
608+ },
609+ },
610+ expectedResponse : & fwserver.CreateResourceResponse {
611+ Diagnostics : []diag.Diagnostic {
612+ diag .NewErrorDiagnostic (
613+ "Missing Resource Identity After Create" ,
614+ "The Terraform Provider unexpectedly returned no resource identity data after having no errors in the resource create. " +
615+ "This is always an issue in the Terraform Provider and should be reported to the provider developers." ,
616+ ),
617+ },
618+ NewIdentity : & tfsdk.ResourceIdentity {
619+ Raw : tftypes .NewValue (testIdentityType , nil ),
620+ Schema : testIdentitySchema ,
621+ },
622+ NewState : & tfsdk.State {
623+ Raw : tftypes .NewValue (testSchemaType , map [string ]tftypes.Value {
624+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
625+ "test_required" : tftypes .NewValue (tftypes .String , "test-plannedstate-value" ),
626+ }),
627+ Schema : testSchema ,
628+ },
629+ Private : testEmptyPrivate ,
630+ },
631+ },
632+ "response-invalid-null-identity" : {
633+ server : & fwserver.Server {
634+ Provider : & testprovider.Provider {},
635+ },
636+ request : & fwserver.CreateResourceRequest {
637+ PlannedState : & tfsdk.Plan {
638+ Raw : tftypes .NewValue (testSchemaType , map [string ]tftypes.Value {
639+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
640+ "test_required" : tftypes .NewValue (tftypes .String , "test-plannedstate-value" ),
641+ }),
642+ Schema : testSchema ,
643+ },
644+ IdentitySchema : testIdentitySchema ,
645+ ResourceSchema : testSchema ,
646+ Resource : & testprovider.ResourceWithIdentity {
647+ Resource : & testprovider.Resource {
648+ CreateMethod : func (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
649+ resp .Diagnostics .Append (resp .Identity .Set (ctx , testIdentitySchemaData {})... )
650+ // Prevent missing resource state error diagnostic
651+ var data testSchemaData
652+
653+ resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
654+ resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
655+ },
656+ },
657+ },
658+ },
659+ expectedResponse : & fwserver.CreateResourceResponse {
660+ Diagnostics : []diag.Diagnostic {
661+ diag .NewErrorDiagnostic (
662+ "Missing Resource Identity After Create" ,
663+ "The Terraform Provider unexpectedly returned no resource identity data after having no errors in the resource create. " +
664+ "This is always an issue in the Terraform Provider and should be reported to the provider developers." ,
665+ ),
666+ },
667+ NewIdentity : & tfsdk.ResourceIdentity {
668+ Raw : tftypes .NewValue (testIdentityType , map [string ]tftypes.Value {
669+ "test_id" : tftypes .NewValue (tftypes .String , nil ),
670+ }),
671+ Schema : testIdentitySchema ,
672+ },
673+ NewState : & tfsdk.State {
674+ Raw : tftypes .NewValue (testSchemaType , map [string ]tftypes.Value {
675+ "test_computed" : tftypes .NewValue (tftypes .String , nil ),
676+ "test_required" : tftypes .NewValue (tftypes .String , "test-plannedstate-value" ),
677+ }),
678+ Schema : testSchema ,
679+ },
680+ Private : testEmptyPrivate ,
681+ },
682+ },
583683 "response-invalid-newidentity" : {
584684 server : & fwserver.Server {
585685 Provider : & testprovider.Provider {},
0 commit comments