diff --git a/builder/virtualbox/common/step_attach_isos.go b/builder/virtualbox/common/step_attach_isos.go index 7f9aa37a8..efbe26254 100644 --- a/builder/virtualbox/common/step_attach_isos.go +++ b/builder/virtualbox/common/step_attach_isos.go @@ -145,14 +145,14 @@ func (s *StepAttachISOs) Cleanup(state multistep.StateBag) { } driver := state.Get("driver").(Driver) + _, ok := state.GetOk("detached_isos") - for _, command := range s.diskUnmountCommands { - // Remove the ISO. Note that this will probably fail since - // stepRemoveDevices does this as well. No big deal. - err := driver.VBoxManage(command...) - if err != nil { - log.Printf("error detaching iso; probably was already detached " + - "in step_remove_devices") + if !ok { + for _, command := range s.diskUnmountCommands { + err := driver.VBoxManage(command...) + if err != nil { + log.Printf("error detaching iso: %s", err) + } } } } diff --git a/builder/virtualbox/common/step_remove_devices.go b/builder/virtualbox/common/step_remove_devices.go index 9c9ace57e..53bc97cca 100644 --- a/builder/virtualbox/common/step_remove_devices.go +++ b/builder/virtualbox/common/step_remove_devices.go @@ -95,6 +95,10 @@ func (s *StepRemoveDevices) Run(ctx context.Context, state multistep.StateBag) m } } + // log that we removed the isos, so we don't waste time trying to do it + // in the step_attach_isos cleanup. + state.Put("detached_isos", true) + return multistep.ActionContinue }