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 {