From a7283f2281b0fee6899cb22206d851f0f8836b6f Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Wed, 6 Sep 2017 10:58:08 +0200 Subject: [PATCH 1/2] Add support for setting labels on GCE instance --- builder/googlecompute/config.go | 1 + builder/googlecompute/driver.go | 1 + builder/googlecompute/driver_gce.go | 1 + builder/googlecompute/step_create_instance.go | 1 + 4 files changed, 4 insertions(+) diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 99c52a704..c4aa79d22 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -36,6 +36,7 @@ type Config struct { ImageDescription string `mapstructure:"image_description"` ImageFamily string `mapstructure:"image_family"` InstanceName string `mapstructure:"instance_name"` + Labels map[string]string `mapstructure:"labels"` MachineType string `mapstructure:"machine_type"` Metadata map[string]string `mapstructure:"metadata"` Network string `mapstructure:"network"` diff --git a/builder/googlecompute/driver.go b/builder/googlecompute/driver.go index a93559e92..60707ac84 100644 --- a/builder/googlecompute/driver.go +++ b/builder/googlecompute/driver.go @@ -65,6 +65,7 @@ type InstanceConfig struct { DiskSizeGb int64 DiskType string Image *Image + Labels map[string]string MachineType string Metadata map[string]string Name string diff --git a/builder/googlecompute/driver_gce.go b/builder/googlecompute/driver_gce.go index 28cb08f6a..0df21eba6 100644 --- a/builder/googlecompute/driver_gce.go +++ b/builder/googlecompute/driver_gce.go @@ -407,6 +407,7 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) { }, }, GuestAccelerators: guestAccelerators, + Labels: c.Labels, MachineType: machineType.SelfLink, Metadata: &compute.Metadata{ Items: metadata, diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index 97b659a9d..a4509354e 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -106,6 +106,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction DiskSizeGb: c.DiskSizeGb, DiskType: c.DiskType, Image: sourceImage, + Labels: c.Labels, MachineType: c.MachineType, Metadata: metadata, Name: name, From a005638e1195703d47d79a4193b530c2ef6bc996 Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Wed, 6 Sep 2017 23:22:51 +0200 Subject: [PATCH 2/2] Document labels set on GCE instance --- website/source/docs/builders/googlecompute.html.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/source/docs/builders/googlecompute.html.md b/website/source/docs/builders/googlecompute.html.md index c17d6a185..891dc401b 100644 --- a/website/source/docs/builders/googlecompute.html.md +++ b/website/source/docs/builders/googlecompute.html.md @@ -204,6 +204,9 @@ builder. - `instance_name` (string) - A name to give the launched instance. Beware that this must be unique. Defaults to `"packer-{{uuid}}"`. +- `labels` (object of key/value strings) - Labels applied to the launched + instance. + - `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`. - `metadata` (object of key/value strings) - Metadata applied to the launched