@@ -219,19 +219,16 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
219219 return fmt .Errorf ("importing resource %s: expected a resource change, got no changes" , resourceName )
220220 }
221221
222- actions := resourceChangeUnderTest .Change .Actions
223- if ! actions .NoOp () {
224- var stdout string
225- err = runProviderCommand (ctx , t , func () error {
226- var err error
227- stdout , err = importWd .SavedPlanRawStdout (ctx )
228- return err
229- }, importWd , providers )
230- if err != nil {
231- return fmt .Errorf ("retrieving formatted plan output: %w" , err )
232- }
222+ change := resourceChangeUnderTest .Change
223+ actions := change .Actions
224+ importing := change .Importing
233225
234- return fmt .Errorf ("importing resource %s: expected a no-op resource action, got %q action with plan \n stdout:\n \n %s" , resourceChangeUnderTest .Address , actions , stdout )
226+ switch {
227+ case importing == nil :
228+ return fmt .Errorf ("importing resource %s: expected an import operation, got %q action with plan \n stdout:\n \n %s" , resourceChangeUnderTest .Address , actions , savedPlanRawStdout (ctx , t , importWd , providers ))
229+
230+ case ! actions .NoOp ():
231+ return fmt .Errorf ("importing resource %s: expected a no-op import operation, got %q action with plan \n stdout:\n \n %s" , resourceChangeUnderTest .Address , actions , savedPlanRawStdout (ctx , t , importWd , providers ))
235232 }
236233
237234 if err := runPlanChecks (ctx , t , plan , step .ImportPlanChecks .PreApply ); err != nil {
@@ -469,3 +466,20 @@ func runImportStateCheckFunction(ctx context.Context, t testing.T, importState *
469466
470467 logging .HelperResourceTrace (ctx , "Called TestStep ImportStateCheck" )
471468}
469+
470+ func savedPlanRawStdout (ctx context.Context , t testing.T , wd * plugintest.WorkingDir , providers * providerFactories ) string {
471+ t .Helper ()
472+
473+ var stdout string
474+
475+ err := runProviderCommand (ctx , t , func () error {
476+ var err error
477+ stdout , err = wd .SavedPlanRawStdout (ctx )
478+ return err
479+ }, wd , providers )
480+
481+ if err != nil {
482+ return fmt .Sprintf ("error retrieving formatted plan output: %w" , err )
483+ }
484+ return stdout
485+ }
0 commit comments