in pkg/terraform/object.go [16:54]
func ListOfObject[T Object](objs []T) cty.Value {
var values []cty.Value
allTypes := make(map[string]cty.Type)
for _, b := range objs {
value := b.EvalContext()
values = append(values, value)
attributeTypes := value.Type().AttributeTypes()
for n, t := range attributeTypes {
if _, ok := allTypes[n]; !ok {
allTypes[n] = t
continue
}
if !allTypes[n].Equals(t) {
if allTypes[n].IsListType() && t.IsListType() {
allTypes[n] = cty.List(mergeObjectType(allTypes[n].ElementType(), t.ElementType()))
continue
}
allTypes[n] = mergeObjectType(allTypes[n], t)
}
}
}
var allFields []string
linq.From(allTypes).Select(func(i interface{}) interface{} {
return i.(linq.KeyValue).Key
}).ToSlice(&allFields)
finalType := cty.ObjectWithOptionalAttrs(allTypes, allFields)
var convertedValues []cty.Value
for _, v := range values {
cv, err := convert.Convert(v, finalType)
if err != nil {
panic(err)
}
convertedValues = append(convertedValues, cv)
}
if len(convertedValues) == 0 {
return cty.ListValEmpty(finalType)
}
return cty.ListVal(convertedValues)
}