From e169013527f8ee4e4dcd750b682ddb2d89cb15b3 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Sat, 26 Apr 2014 12:14:53 +1000 Subject: [PATCH] builder/googlecompute: configure instance name Retain the current default of an instance name generated by UUID, but allow users to choose a specific one. Useful for provisioning with Puppet when a node name is used to select the right manifest. --- builder/googlecompute/config.go | 6 ++++++ builder/googlecompute/step_create_instance.go | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index f769980db..795de6d69 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/mitchellh/packer/common/uuid" "github.com/mitchellh/packer/common" "github.com/mitchellh/packer/packer" ) @@ -19,6 +20,7 @@ type Config struct { ClientSecretsFile string `mapstructure:"client_secrets_file"` ImageName string `mapstructure:"image_name"` ImageDescription string `mapstructure:"image_description"` + InstanceName string `mapstructure:"instance_name"` MachineType string `mapstructure:"machine_type"` Metadata map[string]string `mapstructure:"metadata"` Network string `mapstructure:"network"` @@ -70,6 +72,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { c.ImageName = "packer-{{timestamp}}" } + if c.InstanceName == "" { + c.InstanceName = fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID()) + } + if c.MachineType == "" { c.MachineType = "n1-standard-1" } diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index bfcad4be0..ff94d5d38 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -6,7 +6,6 @@ import ( "time" "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/common/uuid" "github.com/mitchellh/packer/packer" ) @@ -25,7 +24,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction ui := state.Get("ui").(packer.Ui) ui.Say("Creating instance...") - name := fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID()) + name := config.InstanceName errCh, err := driver.RunInstance(&InstanceConfig{ Description: "New instance created by Packer",