diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index e572c441d..6bfee5460 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -125,6 +125,29 @@ func (s *StepCreateInstance) Cleanup(state multistep.StateBag) { "Error: %s", name, err)) } + ui.Message("Instance has been deleted!") state.Put("instance_name", "") + + // Deleting the instance does not remove the boot disk. This cleanup removes + // the disk. + ui.Say("Deleting disk...") + errCh, err = driver.DeleteDisk(config.Zone, config.DiskName) + if err == nil { + select { + case err = <-errCh: + case <-time.After(config.stateTimeout): + err = errors.New("time out while waiting for disk to delete") + } + } + + if err != nil { + ui.Error(fmt.Sprintf( + "Error deleting disk. Please delete it manually.\n\n"+ + "Name: %s\n"+ + "Error: %s", config.InstanceName, err)) + } + + ui.Message("Disk has been deleted!") + return } diff --git a/builder/googlecompute/step_create_instance_test.go b/builder/googlecompute/step_create_instance_test.go index baae10849..f2ccbf57c 100644 --- a/builder/googlecompute/step_create_instance_test.go +++ b/builder/googlecompute/step_create_instance_test.go @@ -39,7 +39,14 @@ func TestStepCreateInstance(t *testing.T) { t.Fatal("should've deleted instance") } if driver.DeleteInstanceZone != config.Zone { - t.Fatalf("bad zone: %#v", driver.DeleteInstanceZone) + t.Fatalf("bad instance zone: %#v", driver.DeleteInstanceZone) + } + + if driver.DeleteDiskName != config.InstanceName { + t.Fatal("should've deleted disk") + } + if driver.DeleteDiskZone != config.Zone { + t.Fatalf("bad disk zone: %#v", driver.DeleteDiskZone) } }