77 "context"
88 "errors"
99 "fmt"
10+ "os"
1011
1112 "github.com/hashicorp/terraform-exec/tfexec"
1213 tfjson "github.com/hashicorp/terraform-json"
@@ -29,6 +30,13 @@ var expectNonEmptyPlanOutputChangesMinTFVersion = tfversion.Version0_14_0
2930func testStepNewConfig (ctx context.Context , t testing.T , c TestCase , wd * plugintest.WorkingDir , step TestStep , providers * providerFactories , stepIndex int , helper * plugintest.Helper ) error {
3031 t .Helper ()
3132
33+ // When `refreshAfterApply` is true, a `Config`-mode test step will invoke
34+ // a refresh before successful completion. This is a compatibility measure
35+ // for test cases that have different -- but semantically-equal -- state
36+ // representations in their test steps. When comparing two states, the
37+ // testing framework is not aware of semantic equality or set equality.
38+ _ , refreshAfterApply := os .LookupEnv (EnvTfAccRefreshAfterApply )
39+
3240 configRequest := teststep.PrepareConfigurationRequest {
3341 Directory : step .ConfigDirectory ,
3442 File : step .ConfigFile ,
@@ -442,13 +450,12 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
442450 }
443451 }
444452
445- // I'm sorry, I'm afraid I can't do that. With one exception.
446- if RefreshAfterApply == "unlocked" && ! step .Destroy && ! step .PlanOnly {
453+ if refreshAfterApply && ! step .Destroy && ! step .PlanOnly {
447454 if len (c .Steps ) > stepIndex + 1 {
448455 // If the next step is a refresh, then we have no need to refresh here
449456 if ! c .Steps [stepIndex + 1 ].RefreshState {
450457 // Echo a searchable message to easily determine when this is no longer being used
451- fmt .Println ("RefreshAfterApply: running apply -refresh-only -refresh=true" )
458+ fmt .Println (EnvTfAccRefreshAfterApply + ":" , " running apply -refresh-only -refresh=true" )
452459 err := runProviderCommandApplyRefreshOnly (ctx , t , wd , providers )
453460 if err != nil {
454461 return fmt .Errorf ("Error running apply refresh-only: %w" , err )
0 commit comments