Skip to content

Commit 9736162

Browse files
authored
helper/resource: Changelogs and test for #602 (#606)
* add changelogs and new test * trace logs * log * single test * cover * revert * quick log attempt * upload some logs on failure * glob * revert test changes
1 parent b053e8e commit 9736162

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'helper/resource: Test steps in `Config` mode using the `TF_ACC_REFRESH_AFTER_APPLY` compatibility flag will now force post-apply plans to refresh.'
3+
time: 2026-02-10T15:39:21.121944-05:00
4+
custom:
5+
Issue: "602"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: BUG FIXES
2+
body: 'helper/resource: Test steps in `Config` mode using `Destroy: true` and `Check` functions will now create an additional destroy plan prior to
3+
running `terraform apply` to avoid a potential "Saved Plan is Stale" error from Terraform.'
4+
time: 2026-02-10T15:43:12.029656-05:00
5+
custom:
6+
Issue: "602"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'helper/resource: Test steps in `Config` mode using the `TF_ACC_REFRESH_AFTER_APPLY` compatibility flag will not refresh if `ExpectNonEmptyPlan` is true.'
3+
time: 2026-02-10T15:46:02.221648-05:00
4+
custom:
5+
Issue: "602"

.github/workflows/ci-go.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
name: test (Go ${{ matrix.go-version }} / TF ${{ matrix.terraform }})
2727
runs-on: ubuntu-latest
2828
strategy:
29+
fail-fast: false
2930
matrix:
3031
go-version: [ '1.25', '1.24' ]
3132
terraform: ${{ fromJSON(vars.TF_VERSIONS_PROTOCOL_V5) }}

helper/resource/testing_new_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
191191
return wd.CreatePlan(ctx, opts...)
192192
})
193193
if err != nil {
194-
return fmt.Errorf("Error running pre-apply plan: %w", err)
194+
return fmt.Errorf("Error running destroy plan after step.Check shimmed state was retrieved: %w", err)
195195
}
196196
}
197197

helper/resource/testing_new_config_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource"
1717
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1818
"github.com/hashicorp/terraform-plugin-testing/statecheck"
19+
"github.com/hashicorp/terraform-plugin-testing/terraform"
1920
"github.com/hashicorp/terraform-plugin-testing/tfversion"
2021
)
2122

@@ -906,3 +907,58 @@ func Test_PostApplyFunc_Called(t *testing.T) {
906907
t.Error("expected ConfigStateChecks spy1 to be called at least once")
907908
}
908909
}
910+
911+
// This regression test ensures that the combination of Config, Destroy, and Check never result in
912+
// a "Saved Plan is Stale" error message, which occurs when the state serial does not match the plan.
913+
//
914+
// This can occur when the refresh that is only done to produce the shimmed "Check" state produces a new state serial.
915+
// Running a fresh plan after refreshing solves that issue, which was introduced in: https://github.com/hashicorp/terraform-plugin-testing/pull/602
916+
func Test_Destroy_Checks_Avoid_Stale_Plan(t *testing.T) {
917+
t.Parallel()
918+
919+
UnitTest(t, TestCase{
920+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
921+
tfversion.SkipBelow(tfversion.Version1_0_0), // ProtoV6ProviderFactories
922+
},
923+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
924+
"test": providerserver.NewProviderServer(testprovider.Provider{
925+
Resources: map[string]testprovider.Resource{
926+
"test_resource": {
927+
CreateResponse: &resource.CreateResponse{
928+
NewState: tftypes.NewValue(
929+
tftypes.Object{
930+
AttributeTypes: map[string]tftypes.Type{
931+
"id": tftypes.String,
932+
},
933+
},
934+
map[string]tftypes.Value{
935+
"id": tftypes.NewValue(tftypes.String, "test"),
936+
},
937+
),
938+
},
939+
SchemaResponse: &resource.SchemaResponse{
940+
Schema: &tfprotov6.Schema{
941+
Block: &tfprotov6.SchemaBlock{
942+
Attributes: []*tfprotov6.SchemaAttribute{
943+
{
944+
Name: "id",
945+
Type: tftypes.String,
946+
Computed: true,
947+
},
948+
},
949+
},
950+
},
951+
},
952+
},
953+
},
954+
}),
955+
},
956+
Steps: []TestStep{
957+
{
958+
Config: `resource "test_resource" "test" {}`,
959+
Destroy: true,
960+
Check: func(s *terraform.State) error { return nil },
961+
},
962+
},
963+
})
964+
}

0 commit comments

Comments
 (0)