Skip to content

Commit e6cadf4

Browse files
committed
Use an environment variable
1 parent 46efbf2 commit e6cadf4

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

helper/resource/compatibility.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

helper/resource/environment_variables.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ const (
3232
// type Config field includes a provider source, such as the terraform
3333
// configuration block required_providers attribute.
3434
EnvTfAccProviderNamespace = "TF_ACC_PROVIDER_NAMESPACE"
35+
36+
// This is an undocumented compatibility flag. When this is set, a
37+
// `Config`-mode test step will invoke a refresh before successful
38+
// completion.
39+
//
40+
// This is a compatibility measure for test cases that have different --
41+
// but semantically-equal -- state representations in their test steps.
42+
// When comparing two states, the testing framework is not aware of
43+
// semantic equality or set equality.
44+
EnvTfAccRefreshAfterApply = "TF_ACC_REFRESH_AFTER_APPLY"
3545
)

helper/resource/testing_new_config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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
2930
func 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

Comments
 (0)