@@ -4576,7 +4576,8 @@ func TestServerApplyResourceChange(t *testing.T) {
4576
4576
action : "delete" ,
4577
4577
resourceType : testServeResourceTypeOneType ,
4578
4578
destroy : func (ctx context.Context , req DeleteResourceRequest , resp * DeleteResourceResponse ) {
4579
- resp .State .Raw = tftypes .NewValue (testServeResourceTypeOneType , nil )
4579
+ // Removing the state prior to the framework should not generate errors
4580
+ resp .State .RemoveResource (ctx )
4580
4581
},
4581
4582
expectedNewState : tftypes .NewValue (testServeResourceTypeOneType , nil ),
4582
4583
},
@@ -4592,7 +4593,8 @@ func TestServerApplyResourceChange(t *testing.T) {
4592
4593
action : "delete" ,
4593
4594
resourceType : testServeResourceTypeOneType ,
4594
4595
destroy : func (ctx context.Context , req DeleteResourceRequest , resp * DeleteResourceResponse ) {
4595
- resp .State .Raw = tftypes .NewValue (testServeResourceTypeOneType , nil )
4596
+ // Removing the state prior to the framework should not generate errors
4597
+ resp .State .RemoveResource (ctx )
4596
4598
resp .Diagnostics .AddAttributeWarning (
4597
4599
tftypes .NewAttributePath ().WithAttributeName ("created_timestamp" ),
4598
4600
"This is a warning" ,
@@ -4641,6 +4643,84 @@ func TestServerApplyResourceChange(t *testing.T) {
4641
4643
},
4642
4644
},
4643
4645
},
4646
+ "one_delete_automatic_removeresource" : {
4647
+ priorState : tftypes .NewValue (testServeResourceTypeOneType , map [string ]tftypes.Value {
4648
+ "name" : tftypes .NewValue (tftypes .String , "hello, world" ),
4649
+ "favorite_colors" : tftypes .NewValue (tftypes.List {ElementType : tftypes .String }, []tftypes.Value {
4650
+ tftypes .NewValue (tftypes .String , "red" ),
4651
+ }),
4652
+ "created_timestamp" : tftypes .NewValue (tftypes .String , "right now I guess" ),
4653
+ }),
4654
+ resource : "test_one" ,
4655
+ action : "delete" ,
4656
+ resourceType : testServeResourceTypeOneType ,
4657
+ destroy : func (ctx context.Context , req DeleteResourceRequest , resp * DeleteResourceResponse ) {
4658
+ // The framework should automatically call resp.State.RemoveResource()
4659
+ },
4660
+ expectedNewState : tftypes .NewValue (testServeResourceTypeOneType , nil ),
4661
+ },
4662
+ "one_delete_diags_warning_automatic_removeresource" : {
4663
+ priorState : tftypes .NewValue (testServeResourceTypeOneType , map [string ]tftypes.Value {
4664
+ "name" : tftypes .NewValue (tftypes .String , "hello, world" ),
4665
+ "favorite_colors" : tftypes .NewValue (tftypes.List {ElementType : tftypes .String }, []tftypes.Value {
4666
+ tftypes .NewValue (tftypes .String , "red" ),
4667
+ }),
4668
+ "created_timestamp" : tftypes .NewValue (tftypes .String , "right now I guess" ),
4669
+ }),
4670
+ resource : "test_one" ,
4671
+ action : "delete" ,
4672
+ resourceType : testServeResourceTypeOneType ,
4673
+ destroy : func (ctx context.Context , req DeleteResourceRequest , resp * DeleteResourceResponse ) {
4674
+ // The framework should automatically call resp.State.RemoveResource()
4675
+ resp .Diagnostics .AddAttributeWarning (
4676
+ tftypes .NewAttributePath ().WithAttributeName ("created_timestamp" ),
4677
+ "This is a warning" ,
4678
+ "just a warning diagnostic, no behavior changes" ,
4679
+ )
4680
+ },
4681
+ expectedNewState : tftypes .NewValue (testServeResourceTypeOneType , nil ),
4682
+ expectedDiags : []* tfprotov6.Diagnostic {
4683
+ {
4684
+ Severity : tfprotov6 .DiagnosticSeverityWarning ,
4685
+ Summary : "This is a warning" ,
4686
+ Detail : "just a warning diagnostic, no behavior changes" ,
4687
+ Attribute : tftypes .NewAttributePath ().WithAttributeName ("created_timestamp" ),
4688
+ },
4689
+ },
4690
+ },
4691
+ "one_delete_diags_error_no_automatic_removeresource" : {
4692
+ priorState : tftypes .NewValue (testServeResourceTypeOneType , map [string ]tftypes.Value {
4693
+ "name" : tftypes .NewValue (tftypes .String , "hello, world" ),
4694
+ "favorite_colors" : tftypes .NewValue (tftypes.List {ElementType : tftypes .String }, []tftypes.Value {
4695
+ tftypes .NewValue (tftypes .String , "red" ),
4696
+ }),
4697
+ "created_timestamp" : tftypes .NewValue (tftypes .String , "right now I guess" ),
4698
+ }),
4699
+ resource : "test_one" ,
4700
+ action : "delete" ,
4701
+ resourceType : testServeResourceTypeOneType ,
4702
+ destroy : func (ctx context.Context , req DeleteResourceRequest , resp * DeleteResourceResponse ) {
4703
+ // The framework should NOT automatically call resp.State.RemoveResource()
4704
+ resp .Diagnostics .AddError (
4705
+ "This is an error" ,
4706
+ "Something went wrong, keep the old state around" ,
4707
+ )
4708
+ },
4709
+ expectedNewState : tftypes .NewValue (testServeResourceTypeOneType , map [string ]tftypes.Value {
4710
+ "name" : tftypes .NewValue (tftypes .String , "hello, world" ),
4711
+ "favorite_colors" : tftypes .NewValue (tftypes.List {ElementType : tftypes .String }, []tftypes.Value {
4712
+ tftypes .NewValue (tftypes .String , "red" ),
4713
+ }),
4714
+ "created_timestamp" : tftypes .NewValue (tftypes .String , "right now I guess" ),
4715
+ }),
4716
+ expectedDiags : []* tfprotov6.Diagnostic {
4717
+ {
4718
+ Severity : tfprotov6 .DiagnosticSeverityError ,
4719
+ Summary : "This is an error" ,
4720
+ Detail : "Something went wrong, keep the old state around" ,
4721
+ },
4722
+ },
4723
+ },
4644
4724
"two_create" : {
4645
4725
plannedState : tftypes .NewValue (testServeResourceTypeTwoType , map [string ]tftypes.Value {
4646
4726
"id" : tftypes .NewValue (tftypes .String , "test-instance" ),
0 commit comments