@@ -132,6 +132,8 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
132132 // use this to track last step successfully applied
133133 // acts as default for import tests
134134 var appliedCfg string
135+ var appliedDirCfg string
136+ var appliedFileCfg string
135137 var stepNumber int
136138
137139 for stepIndex , step := range c .Steps {
@@ -141,14 +143,16 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
141143
142144 stepNumber = stepIndex + 1 // 1-based indexing for humans
143145
146+ currentTestStepConfigRequest := config.TestStepConfigRequest {
147+ StepNumber : stepNumber ,
148+ TestName : t .Name (),
149+ }
150+
144151 configRequest := teststep.PrepareConfigurationRequest {
145- Directory : step .ConfigDirectory ,
146- File : step .ConfigFile ,
147- Raw : step .Config ,
148- TestStepConfigRequest : config.TestStepConfigRequest {
149- StepNumber : stepNumber ,
150- TestName : t .Name (),
151- },
152+ Directory : step .ConfigDirectory ,
153+ File : step .ConfigFile ,
154+ Raw : step .Config ,
155+ TestStepConfigRequest : currentTestStepConfigRequest ,
152156 }.Exec ()
153157
154158 cfg := teststep .Configuration (configRequest )
@@ -281,7 +285,7 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
281285 if step .ImportState {
282286 logging .HelperResourceTrace (ctx , "TestStep is ImportState mode" )
283287
284- err := testStepNewImportState (ctx , t , helper , wd , step , appliedCfg , providers , stepNumber )
288+ err := testStepNewImportState (ctx , t , helper , wd , step , appliedCfg , appliedDirCfg , appliedFileCfg , providers , stepNumber )
285289 if step .ExpectError != nil {
286290 logging .HelperResourceDebug (ctx , "Checking TestStep ExpectError" )
287291 if err == nil {
@@ -430,6 +434,11 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest
430434
431435 logging .HelperResourceDebug (ctx , "Finished TestStep" )
432436
437+ // Store the ConfigDirectory and ConfigFile from the current step
438+ // so they can be used by subsequent ImportState steps if not explicitly set.
439+ appliedDirCfg = step .ConfigDirectory .Exec (currentTestStepConfigRequest )
440+ appliedFileCfg = step .ConfigFile .Exec (currentTestStepConfigRequest )
441+
433442 continue
434443 }
435444
0 commit comments