From edc8e828a89036c6d02871c528ed028f61a2732f Mon Sep 17 00:00:00 2001 From: Pam Selle Date: Tue, 23 Jun 2020 13:35:05 -0400 Subject: [PATCH] function/stdlib: Allow empty maps in merge function --- cty/function/stdlib/collection.go | 3 +++ cty/function/stdlib/collection_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cty/function/stdlib/collection.go b/cty/function/stdlib/collection.go index b2ce062a..121985f6 100644 --- a/cty/function/stdlib/collection.go +++ b/cty/function/stdlib/collection.go @@ -762,6 +762,9 @@ var MergeFunc = function.New(&function.Spec{ case allNull: return cty.NullVal(retType), nil case retType.IsMapType(): + if len(outputMap) == 0 { + return cty.MapValEmpty(retType.ElementType()), nil + } return cty.MapVal(outputMap), nil case retType.IsObjectType(), retType.Equals(cty.DynamicPseudoType): return cty.ObjectVal(outputMap), nil diff --git a/cty/function/stdlib/collection_test.go b/cty/function/stdlib/collection_test.go index d1b7dc2a..2d5acc09 100644 --- a/cty/function/stdlib/collection_test.go +++ b/cty/function/stdlib/collection_test.go @@ -506,6 +506,14 @@ func TestMerge(t *testing.T) { cty.NilVal, true, }, + { // Empty maps are allowed in merge + []cty.Value{ + cty.MapValEmpty(cty.String), + cty.MapValEmpty(cty.String), + }, + cty.MapValEmpty(cty.String), + false, + }, } for _, test := range tests {