@@ -110,13 +110,15 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
110110 continue
111111 }
112112
113+ coll , marks := coll .Unmark ()
114+
113115 if ! coll .CanIterateElements () {
114116 return cty .UnknownVal (impliedType ), path .NewErrorf ("must be a list" )
115117 }
116118 l := coll .LengthInt ()
117119
118120 if l == 0 {
119- attrs [typeName ] = cty .ListValEmpty (blockS .ImpliedType ())
121+ attrs [typeName ] = cty .ListValEmpty (blockS .ImpliedType ()). WithMarks ( marks )
120122 continue
121123 }
122124 elems := make ([]cty.Value , 0 , l )
@@ -132,7 +134,7 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
132134 elems = append (elems , val )
133135 }
134136 }
135- attrs [typeName ] = cty .ListVal (elems )
137+ attrs [typeName ] = cty .ListVal (elems ). WithMarks ( marks )
136138 default :
137139 attrs [typeName ] = cty .ListValEmpty (blockS .ImpliedType ())
138140 }
@@ -150,14 +152,15 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
150152 attrs [typeName ] = cty .UnknownVal (cty .Set (blockS .ImpliedType ()))
151153 continue
152154 }
155+ coll , marks := coll .Unmark ()
153156
154157 if ! coll .CanIterateElements () {
155- return cty .UnknownVal (impliedType ), path .NewErrorf ("must be a set" )
158+ return cty .UnknownVal (impliedType ), path .NewErrorf ("cannot iterate over %#v" , coll )
156159 }
157160 l := coll .LengthInt ()
158161
159162 if l == 0 {
160- attrs [typeName ] = cty .SetValEmpty (blockS .ImpliedType ())
163+ attrs [typeName ] = cty .SetValEmpty (blockS .ImpliedType ()). WithMarks ( marks )
161164 continue
162165 }
163166 elems := make ([]cty.Value , 0 , l )
@@ -173,7 +176,7 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
173176 elems = append (elems , val )
174177 }
175178 }
176- attrs [typeName ] = cty .SetVal (elems )
179+ attrs [typeName ] = cty .SetVal (elems ). WithMarks ( marks )
177180 default :
178181 attrs [typeName ] = cty .SetValEmpty (blockS .ImpliedType ())
179182 }
@@ -191,13 +194,14 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
191194 attrs [typeName ] = cty .UnknownVal (cty .Map (blockS .ImpliedType ()))
192195 continue
193196 }
197+ coll , marks := coll .Unmark ()
194198
195199 if ! coll .CanIterateElements () {
196200 return cty .UnknownVal (impliedType ), path .NewErrorf ("must be a map" )
197201 }
198202 l := coll .LengthInt ()
199203 if l == 0 {
200- attrs [typeName ] = cty .MapValEmpty (blockS .ImpliedType ())
204+ attrs [typeName ] = cty .MapValEmpty (blockS .ImpliedType ()). WithMarks ( marks )
201205 continue
202206 }
203207 elems := make (map [string ]cty.Value )
@@ -220,24 +224,14 @@ func (b *Block) coerceValue(in cty.Value, path cty.Path) (cty.Value, error) {
220224 // If the attribute values here contain any DynamicPseudoTypes,
221225 // the concrete type must be an object.
222226 useObject := false
223- switch {
224- case coll .Type ().IsObjectType ():
227+ if coll .Type ().IsObjectType () || blockS .ImpliedType ().HasDynamicTypes () {
225228 useObject = true
226- default :
227- // It's possible that we were given a map, and need to coerce it to an object
228- ety := coll .Type ().ElementType ()
229- for _ , v := range elems {
230- if ! v .Type ().Equals (ety ) {
231- useObject = true
232- break
233- }
234- }
235229 }
236230
237231 if useObject {
238- attrs [typeName ] = cty .ObjectVal (elems )
232+ attrs [typeName ] = cty .ObjectVal (elems ). WithMarks ( marks )
239233 } else {
240- attrs [typeName ] = cty .MapVal (elems )
234+ attrs [typeName ] = cty .MapVal (elems ). WithMarks ( marks )
241235 }
242236 default :
243237 attrs [typeName ] = cty .MapValEmpty (blockS .ImpliedType ())
0 commit comments