github.com/sneal/packer@v0.5.2/builder/virtualbox/common/shutdown_config.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/packer/packer" 6 "time" 7 ) 8 9 type ShutdownConfig struct { 10 ShutdownCommand string `mapstructure:"shutdown_command"` 11 RawShutdownTimeout string `mapstructure:"shutdown_timeout"` 12 13 ShutdownTimeout time.Duration `` 14 } 15 16 func (c *ShutdownConfig) Prepare(t *packer.ConfigTemplate) []error { 17 if c.RawShutdownTimeout == "" { 18 c.RawShutdownTimeout = "5m" 19 } 20 21 templates := map[string]*string{ 22 "shutdown_command": &c.ShutdownCommand, 23 "shutdown_timeout": &c.RawShutdownTimeout, 24 } 25 26 errs := make([]error, 0) 27 for n, ptr := range templates { 28 var err error 29 *ptr, err = t.Process(*ptr, nil) 30 if err != nil { 31 errs = append(errs, fmt.Errorf("Error processing %s: %s", n, err)) 32 } 33 } 34 35 var err error 36 c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout) 37 if err != nil { 38 errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err)) 39 } 40 41 return errs 42 }