Make the googlecompute builder label the resulting image.

... so that it's possible to find images matching particular characteristics more easily.
This commit is contained in:
Peter Mounce 2017-09-18 15:44:01 +01:00
parent 4ce381cae7
commit 8789ae72e8
4 changed files with 5 additions and 4 deletions

View File

@ -11,7 +11,7 @@ import (
type Driver interface {
// CreateImage creates an image from the given disk in Google Compute
// Engine.
CreateImage(name, description, family, zone, disk string) (<-chan *Image, <-chan error)
CreateImage(name, description, family, zone, disk string, labels map[string]string) (<-chan *Image, <-chan error)
// DeleteImage deletes the image with the given name.
DeleteImage(name string) <-chan error

View File

@ -98,11 +98,12 @@ func NewDriverGCE(ui packer.Ui, p string, a *AccountFile) (Driver, error) {
}, nil
}
func (d *driverGCE) CreateImage(name, description, family, zone, disk string) (<-chan *Image, <-chan error) {
func (d *driverGCE) CreateImage(name, description, family, zone, disk string, labels map[string]string) (<-chan *Image, <-chan error) {
gce_image := &compute.Image{
Description: description,
Name: name,
Family: family,
Labels: labels,
SourceDisk: fmt.Sprintf("%s%s/zones/%s/disks/%s", d.service.BasePath, d.projectId, zone, disk),
SourceType: "RAW",
}

View File

@ -39,7 +39,7 @@ func (s *StepCreateImage) Run(state multistep.StateBag) multistep.StepAction {
imageCh, errCh := driver.CreateImage(
config.ImageName, config.ImageDescription, config.ImageFamily, config.Zone,
config.DiskName)
config.DiskName, config.Labels)
var err error
select {
case err = <-errCh:

View File

@ -205,7 +205,7 @@ builder.
this must be unique. Defaults to `"packer-{{uuid}}"`.
- `labels` (object of key/value strings) - Key/value pair labels to apply to
the launched instance.
the launched instance and the created image.
- `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`.