Merge pull request #3918 from nouney/f-googlecompute-force
builder/googlecompute: -force option
This commit is contained in:
commit
06fd2a0b67
|
@ -52,6 +52,7 @@ type Config struct {
|
|||
Account AccountFile
|
||||
privateKeyBytes []byte
|
||||
stateTimeout time.Duration
|
||||
imageAlreadyExists bool
|
||||
ctx interpolate.Context
|
||||
}
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@ func (s *StepCheckExistingImage) Run(state multistep.StateBag) multistep.StepAct
|
|||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
ui.Say("Checking image does not exist...")
|
||||
exists := d.ImageExists(c.ImageName)
|
||||
if exists {
|
||||
err := fmt.Errorf("Image %s already exists", c.ImageName)
|
||||
c.imageAlreadyExists = d.ImageExists(c.ImageName)
|
||||
if !c.PackerForce && c.imageAlreadyExists {
|
||||
err := fmt.Errorf("Image %s already exists.\n"+
|
||||
"Use the force flag to delete it prior to building.", c.ImageName)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,19 @@ func (s *StepCreateImage) Run(state multistep.StateBag) multistep.StepAction {
|
|||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
if config.PackerForce && config.imageAlreadyExists {
|
||||
ui.Say("Deleting previous image...")
|
||||
|
||||
errCh := driver.DeleteImage(config.ImageName)
|
||||
err := <-errCh
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error deleting image: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
ui.Say("Creating image...")
|
||||
|
||||
imageCh, errCh := driver.CreateImage(
|
||||
|
|
Loading…
Reference in New Issue