Merge pull request #1065 from brettporter/gce_instance_name

builder/googlecompute: configure instance name
This commit is contained in:
Mitchell Hashimoto 2014-04-26 10:58:27 -07:00
commit 15c2ca955e
2 changed files with 7 additions and 2 deletions

View File

@ -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"
}

View File

@ -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",