diff --git a/packer/template.go b/packer/template.go index 205a54c32..50b1fffd6 100644 --- a/packer/template.go +++ b/packer/template.go @@ -24,6 +24,7 @@ type rawTemplate struct { Description string Builders []map[string]interface{} Hooks map[string][]string + Push PushConfig PostProcessors []interface{} `mapstructure:"post-processors"` Provisioners []map[string]interface{} Variables map[string]interface{} @@ -36,10 +37,19 @@ type Template struct { Variables map[string]RawVariable Builders map[string]RawBuilderConfig Hooks map[string][]string + Push *PushConfig PostProcessors [][]RawPostProcessorConfig Provisioners []RawProvisionerConfig } +// PushConfig is the configuration structure for the push settings. +type PushConfig struct { + Name string + Include []string + Exclude []string + VCS bool +} + // The RawBuilderConfig struct represents a raw, unprocessed builder // configuration. It contains the name of the builder as well as the // raw configuration. If requested, this is used to compile into a full @@ -154,6 +164,7 @@ func ParseTemplate(data []byte, vars map[string]string) (t *Template, err error) t.Variables = make(map[string]RawVariable) t.Builders = make(map[string]RawBuilderConfig) t.Hooks = rawTpl.Hooks + t.Push = &rawTpl.Push t.PostProcessors = make([][]RawPostProcessorConfig, len(rawTpl.PostProcessors)) t.Provisioners = make([]RawProvisionerConfig, len(rawTpl.Provisioners)) diff --git a/packer/template_test.go b/packer/template_test.go index 6feff138a..d42895665 100644 --- a/packer/template_test.go +++ b/packer/template_test.go @@ -541,6 +541,41 @@ func TestParseTemplate_ProvisionerPauseBefore(t *testing.T) { } } +func TestParseTemplateFile_push(t *testing.T) { + data := ` + { + "builders": [{"type": "something"}], + + "push": { + "name": "hello", + "include": ["one"], + "exclude": ["two"] + } + } + ` + + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("err: %s", err) + } + tf.Write([]byte(data)) + tf.Close() + + result, err := ParseTemplateFile(tf.Name(), nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + expected := &PushConfig{ + Name: "hello", + Include: []string{"one"}, + Exclude: []string{"two"}, + } + if !reflect.DeepEqual(result.Push, expected) { + t.Fatalf("bad: %#v", result.Push) + } +} + func TestParseTemplate_Variables(t *testing.T) { data := ` {