Skip to content
9 changes: 9 additions & 0 deletions helper/resource/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ func runProviderCommandApply(ctx context.Context, t testing.T, wd *plugintest.Wo
return runProviderCommand(ctx, t, wd, factories, fn)
}

func runProviderCommandApplyRefreshOnly(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, factories *providerFactories) error {
t.Helper()

fn := func() error {
return wd.Apply(ctx, tfexec.Refresh(true), tfexec.RefreshOnly(true))
}
return runProviderCommand(ctx, t, wd, factories, fn)
}

func runProviderCommandCreatePlan(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, factories *providerFactories) error {
t.Helper()

Expand Down
3 changes: 3 additions & 0 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2142,3 +2142,6 @@ func checkIfIndexesIntoTypeSetPair(keyFirst, keySecond string, f TestCheckFunc)
return err
}
}

// Deprecated: no guarantee of future support.
var DeprecatedCompatibilityFlagRefreshAfterApply string
8 changes: 8 additions & 0 deletions helper/resource/testing_new_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
}
}

// I'm sorry, I'm afraid I can't do that. With one exception.
if DeprecatedCompatibilityFlagRefreshAfterApply == "unlocked" && !step.Destroy && !step.PlanOnly {
err := runProviderCommandApplyRefreshOnly(ctx, t, wd, providers)
if err != nil {
return fmt.Errorf("Error running apply refresh-only: %w", err)
}
}

return nil
}