github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/lxd/config.go (about) 1 package lxd 2 3 import ( 4 "fmt" 5 "github.com/hashicorp/packer/common" 6 "github.com/hashicorp/packer/helper/config" 7 "github.com/hashicorp/packer/packer" 8 "github.com/hashicorp/packer/template/interpolate" 9 "github.com/mitchellh/mapstructure" 10 "time" 11 ) 12 13 type Config struct { 14 common.PackerConfig `mapstructure:",squash"` 15 OutputImage string `mapstructure:"output_image"` 16 ContainerName string `mapstructure:"container_name"` 17 CommandWrapper string `mapstructure:"command_wrapper"` 18 Image string `mapstructure:"image"` 19 InitTimeout time.Duration 20 21 ctx interpolate.Context 22 } 23 24 func NewConfig(raws ...interface{}) (*Config, error) { 25 var c Config 26 27 var md mapstructure.Metadata 28 err := config.Decode(&c, &config.DecodeOpts{ 29 Metadata: &md, 30 Interpolate: true, 31 }, raws...) 32 if err != nil { 33 return nil, err 34 } 35 36 // Accumulate any errors 37 var errs *packer.MultiError 38 39 if c.ContainerName == "" { 40 c.ContainerName = fmt.Sprintf("packer-%s", c.PackerBuildName) 41 } 42 43 if c.OutputImage == "" { 44 c.OutputImage = c.ContainerName 45 } 46 47 if c.CommandWrapper == "" { 48 c.CommandWrapper = "{{.Command}}" 49 } 50 51 if c.Image == "" { 52 errs = packer.MultiErrorAppend(errs, fmt.Errorf("`image` is a required parameter for LXD. Please specify an image by alias or fingerprint. e.g. `ubuntu-daily:x`")) 53 } 54 55 if errs != nil && len(errs.Errors) > 0 { 56 return nil, errs 57 } 58 59 return &c, nil 60 }