add 30 minute timeout for destroying a VM

This commit is contained in:
Megan Marsh 2019-04-23 12:55:59 -07:00
parent b1ffc1c814
commit f7c1b5e940
1 changed files with 9 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package common
import (
"context"
"fmt"
"log"
"time"
"github.com/hashicorp/packer/helper/multistep"
@ -66,12 +67,19 @@ func (s *StepRegister) Cleanup(state multistep.StateBag) {
ui.Error(fmt.Sprintf("Error destroying VM: %s", err))
}
// Wait for the machine to actually destroy
start := time.Now()
for {
destroyed, _ := remoteDriver.IsDestroyed()
destroyed, err := remoteDriver.IsDestroyed()
if destroyed {
break
}
log.Printf("error destroying vm: %s", err)
time.Sleep(1 * time.Second)
if time.Since(start) >= time.Duration(30*time.Minute) {
ui.Error("Error unregistering VM; timed out. You may " +
"need to manually clean up your machine")
break
}
}
}
}