From 736fda16136c42da5217e27c3807f4ff3c907173 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 18 Jul 2019 15:01:00 +0100 Subject: [PATCH] lang/funcs: Pass through empty list in chunklist --- lang/funcs/collection.go | 4 ++++ lang/funcs/collection_test.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index fd0de9ea5f61..5f28867a04f8 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -392,6 +392,10 @@ var ChunklistFunc = function.New(&function.Spec{ return cty.UnknownVal(retType), nil } + if listVal.LengthInt() == 0 { + return cty.ListValEmpty(listVal.Type()), nil + } + var size int err = gocty.FromCtyValue(args[1], &size) if err != nil { diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index ba79ee33b3a9..334a98e7a812 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -1087,6 +1087,12 @@ func TestChunklist(t *testing.T) { cty.UnknownVal(cty.List(cty.List(cty.String))), false, }, + { + cty.ListValEmpty(cty.String), + cty.NumberIntVal(3), + cty.ListValEmpty(cty.List(cty.String)), + false, + }, } for i, test := range tests {