github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/triton/source_machine_config.go (about) 1 package triton 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/packer/template/interpolate" 7 ) 8 9 // SourceMachineConfig represents the configuration to run a machine using 10 // the SDC API in order for provisioning to take place. 11 type SourceMachineConfig struct { 12 MachineName string `mapstructure:"source_machine_name"` 13 MachinePackage string `mapstructure:"source_machine_package"` 14 MachineImage string `mapstructure:"source_machine_image"` 15 MachineNetworks []string `mapstructure:"source_machine_networks"` 16 MachineMetadata map[string]string `mapstructure:"source_machine_metadata"` 17 MachineTags map[string]string `mapstructure:"source_machine_tags"` 18 MachineFirewallEnabled bool `mapstructure:"source_machine_firewall_enabled"` 19 } 20 21 // Prepare performs basic validation on a SourceMachineConfig struct. 22 func (c *SourceMachineConfig) Prepare(ctx *interpolate.Context) []error { 23 var errs []error 24 25 if c.MachinePackage == "" { 26 errs = append(errs, fmt.Errorf("A source_machine_package must be specified")) 27 } 28 29 if c.MachineImage == "" { 30 errs = append(errs, fmt.Errorf("A source_machine_image must be specified")) 31 } 32 33 if c.MachineNetworks == nil { 34 c.MachineNetworks = []string{} 35 } 36 37 if c.MachineMetadata == nil { 38 c.MachineMetadata = make(map[string]string) 39 } 40 41 if c.MachineTags == nil { 42 c.MachineTags = make(map[string]string) 43 } 44 45 if len(errs) > 0 { 46 return errs 47 } 48 49 return nil 50 }