forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_check_existing_image.go
33 lines (27 loc) · 1019 Bytes
/
step_check_existing_image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package googlecompute
import (
"fmt"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
// StepCheckExistingImage represents a Packer build step that checks if the
// target image already exists, and aborts immediately if so.
type StepCheckExistingImage int
// Run executes the Packer build step that checks if the image already exists.
func (s *StepCheckExistingImage) Run(state multistep.StateBag) multistep.StepAction {
c := state.Get("config").(*Config)
d := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
ui.Say("Checking image does not exist...")
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
}
// Cleanup.
func (s *StepCheckExistingImage) Cleanup(state multistep.StateBag) {}