Commit 5ff86ae1 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #2367 from mitchellh/b-build-type

helper/config: copy buildname/buildtype properly
parents 8fd673ff ac444acc
...@@ -42,6 +42,8 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { ...@@ -42,6 +42,8 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
if config.InterpolateContext == nil { if config.InterpolateContext == nil {
config.InterpolateContext = ctx config.InterpolateContext = ctx
} else { } else {
config.InterpolateContext.BuildName = ctx.BuildName
config.InterpolateContext.BuildType = ctx.BuildType
config.InterpolateContext.TemplatePath = ctx.TemplatePath config.InterpolateContext.TemplatePath = ctx.TemplatePath
config.InterpolateContext.UserVariables = ctx.UserVariables config.InterpolateContext.UserVariables = ctx.UserVariables
} }
......
...@@ -74,6 +74,36 @@ func TestDecode(t *testing.T) { ...@@ -74,6 +74,36 @@ func TestDecode(t *testing.T) {
}, },
}, },
}, },
"build name": {
[]interface{}{
map[string]interface{}{
"name": "{{build_name}}",
},
map[string]interface{}{
"packer_build_name": "foo",
},
},
&Target{
Name: "foo",
},
nil,
},
"build type": {
[]interface{}{
map[string]interface{}{
"name": "{{build_type}}",
},
map[string]interface{}{
"packer_builder_type": "foo",
},
},
&Target{
Name: "foo",
},
nil,
},
} }
for k, tc := range cases { for k, tc := range cases {
......
...@@ -71,7 +71,7 @@ func funcGenBuildName(ctx *Context) interface{} { ...@@ -71,7 +71,7 @@ func funcGenBuildName(ctx *Context) interface{} {
func funcGenBuildType(ctx *Context) interface{} { func funcGenBuildType(ctx *Context) interface{} {
return func() (string, error) { return func() (string, error) {
if ctx == nil || ctx.BuildType == "" { if ctx == nil || ctx.BuildType == "" {
return "", errors.New("build_name not available") return "", errors.New("build_type not available")
} }
return ctx.BuildType, nil return ctx.BuildType, nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment