diff --git a/provisioner/template.go b/provisioner/template.go index 1b7cacfa..f5512fe7 100644 --- a/provisioner/template.go +++ b/provisioner/template.go @@ -127,6 +127,7 @@ func renderTemplate(context *templateContext, file string) (string, error) { "awsValidID": awsValidID, "indent": sprig.GenericFuncMap()["indent"], "dict": dict, + "list": list, "scaleQuantity": scaleQuantity, "instanceTypeCPUQuantity": func(instanceType string) (string, error) { return instanceTypeCPUQuantity(context, instanceType) @@ -275,6 +276,10 @@ func dict(args ...interface{}) (map[string]interface{}, error) { return dict, nil } +func list(args ...interface{}) []interface{} { + return args +} + // accountID returns just the ID part of an account func accountID(account string) (string, error) { items := strings.Split(account, ":") diff --git a/provisioner/template_test.go b/provisioner/template_test.go index 55ec40cd..46b0d637 100644 --- a/provisioner/template_test.go +++ b/provisioner/template_test.go @@ -1253,6 +1253,29 @@ func TestDictInvalidArgs(t *testing.T) { } } +func TestList(t *testing.T) { + result, err := renderSingle( + t, + ` +{{- $alist := list + "foo" + "bar" + 1 +}} +{{- range $i, $v := $alist }} +{{ $i }}={{ $v }} +{{- end }} +`, + nil) + + require.NoError(t, err) + require.EqualValues(t, ` +0=foo +1=bar +2=1 +`, result) +} + func TestScaleQuantity(t *testing.T) { for _, tc := range []struct { name string