-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
58 lines (48 loc) · 1.35 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"errors"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
)
type Config struct {
common.PackerConfig `mapstructure:",squash"`
Name string `mapstructure:"box_name"`
URL string `mapstructure:"box_url"`
Version string `mapstructure:"box_version"`
Provider string `mapstructure:"box_provider"`
BoxFile string `mapstructure:"box_file"`
BuilderConfig map[string]interface{} `mapstructure:"builder"`
ctx interpolate.Context
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &c.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"builder",
},
},
}, raws...)
if err != nil {
return nil, nil, err
}
var errs *packer.MultiError
if c.Name == "" {
errs = packer.MultiErrorAppend(errs, errors.New("box_name is required"))
}
if c.Provider == "" {
errs = packer.MultiErrorAppend(errs, errors.New("box_provider is required"))
}
if c.BoxFile == "" {
errs = packer.MultiErrorAppend(errs, errors.New("box_file is required"))
}
// Check for any errors.
if errs != nil && len(errs.Errors) > 0 {
return nil, nil, errs
}
return c, nil, nil
}