Commit d5981c69 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

common: config strings to slices [GH-950]

parent edcb8fea
...@@ -14,6 +14,9 @@ FEATURES: ...@@ -14,6 +14,9 @@ FEATURES:
IMPROVEMENTS: IMPROVEMENTS:
* core: RPC transport between plugins switched to MessagePack * core: RPC transport between plugins switched to MessagePack
* core: Templates array values can now be comma separated strings.
Most importantly, this allows for user variables to fill
array configurations. [GH-950]
* builder/amazon: Added `ssh_private_key_file` option [GH-971] * builder/amazon: Added `ssh_private_key_file` option [GH-971]
* builder/amazon: Added `ami_virtualization_type` option [GH-1021] * builder/amazon: Added `ami_virtualization_type` option [GH-1021]
* builder/googlecompute: Configurable instance name. [GH-1065] * builder/googlecompute: Configurable instance name. [GH-1065]
......
...@@ -68,7 +68,10 @@ func DecodeConfig(target interface{}, raws ...interface{}) (*mapstructure.Metada ...@@ -68,7 +68,10 @@ func DecodeConfig(target interface{}, raws ...interface{}) (*mapstructure.Metada
var md mapstructure.Metadata var md mapstructure.Metadata
decoderConfig := &mapstructure.DecoderConfig{ decoderConfig := &mapstructure.DecoderConfig{
DecodeHook: decodeHook, DecodeHook: mapstructure.ComposeDecodeHookFunc(
decodeHook,
mapstructure.StringToSliceHookFunc(","),
),
Metadata: &md, Metadata: &md,
Result: target, Result: target,
WeaklyTypedInput: true, WeaklyTypedInput: true,
......
...@@ -95,6 +95,33 @@ func TestDecodeConfig(t *testing.T) { ...@@ -95,6 +95,33 @@ func TestDecodeConfig(t *testing.T) {
} }
} }
// This test tests the case that a user var is used for an integer
// configuration.
func TestDecodeConfig_stringToSlice(t *testing.T) {
type Local struct {
Val []string
}
raw := map[string]interface{}{
"packer_user_variables": map[string]string{
"foo": "bar",
},
"val": "foo,{{user `foo`}}",
}
var result Local
_, err := DecodeConfig(&result, raw)
if err != nil {
t.Fatalf("err: %s", err)
}
expected := []string{"foo", "bar"}
if !reflect.DeepEqual(result.Val, expected) {
t.Fatalf("invalid: %#v", result.Val)
}
}
// This test tests the case that a user var is used for an integer // This test tests the case that a user var is used for an integer
// configuration. // configuration.
func TestDecodeConfig_userVarConversion(t *testing.T) { func TestDecodeConfig_userVarConversion(t *testing.T) {
......
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