@@ -202,36 +202,37 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest
202202
203203 logging .HelperResourceDebug (ctx , fmt .Sprintf ("ImportBlockWithId: %d resource changes" , len (plan .ResourceChanges )))
204204
205- for _ , rc := range plan .ResourceChanges {
206- if rc .Address != resourceName {
207- // we're only interested in the changes for the resource being imported
208- continue
209- }
210- if rc .Change != nil && rc .Change .Actions != nil {
211- // should this be length checked and used as a condition, if it's a no-op then there shouldn't be any other changes here
212- for _ , action := range rc .Change .Actions {
213- if action != "no-op" {
214- var stdout string
215- err = runProviderCommand (ctx , t , func () error {
216- var err error
217- stdout , err = importWd .SavedPlanRawStdout (ctx )
218- return err
219- }, importWd , providers )
220- if err != nil {
221- return fmt .Errorf ("retrieving formatted plan output: %w" , err )
222- }
223-
224- return fmt .Errorf ("importing resource %s: expected a no-op resource action, got %q action with plan \n stdout:\n \n %s" , rc .Address , action , stdout )
225- }
226- }
205+ // Verify reasonable things about the plan
206+ var resourceChangeUnderTest * tfjson.ResourceChange
207+
208+ if len (plan .ResourceChanges ) == 0 {
209+ return fmt .Errorf ("importing resource %s: expected a resource change, got no changes" , resourceName )
210+ }
211+
212+ for _ , change := range plan .ResourceChanges {
213+ if change .Address == resourceName {
214+ resourceChangeUnderTest = change
227215 }
228216 }
229217
230- if len ( plan . ResourceChanges ) == 0 {
218+ if resourceChangeUnderTest == nil || resourceChangeUnderTest . Change == nil || resourceChangeUnderTest . Change . Actions == nil {
231219 return fmt .Errorf ("importing resource %s: expected a resource change, got no changes" , resourceName )
232220 }
233221
234- // TODO compare plan to state from previous step
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+ }
233+
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 )
235+ }
235236
236237 if err := runPlanChecks (ctx , t , plan , step .ImportPlanChecks .PreApply ); err != nil {
237238 return err
0 commit comments