@@ -195,27 +195,47 @@ func exprConstraintFromSchemaAttribute(attr *tfjson.SchemaAttribute) schema.Cons
195
195
return convertAttributeTypeToConstraint (attr .AttributeType )
196
196
}
197
197
if attr .AttributeNestedType != nil {
198
+ var attrType cty.Type
199
+ var cons schema.Constraint
200
+
201
+ objType := convertJsonAttributesToCtyObject (attr .AttributeNestedType .Attributes )
202
+ objectCons := convertJsonAttributesToObjectConstraint (attr .AttributeNestedType .Attributes )
203
+
198
204
switch attr .AttributeNestedType .NestingMode {
199
205
case tfjson .SchemaNestingModeSingle :
200
- return convertJsonAttributesToObjectConstraint (attr .AttributeNestedType .Attributes )
206
+ attrType = objType
207
+ cons = objectCons
201
208
case tfjson .SchemaNestingModeList :
202
- return schema.List {
203
- Elem : convertJsonAttributesToObjectConstraint (attr .AttributeNestedType .Attributes ),
209
+ attrType = cty .List (objType )
210
+ cons = schema.List {
211
+ Elem : objectCons ,
204
212
MinItems : attr .AttributeNestedType .MinItems ,
205
213
MaxItems : attr .AttributeNestedType .MaxItems ,
206
214
}
207
215
case tfjson .SchemaNestingModeSet :
208
- return schema.Set {
209
- Elem : convertJsonAttributesToObjectConstraint (attr .AttributeNestedType .Attributes ),
216
+ attrType = cty .Set (objType )
217
+ cons = schema.Set {
218
+ Elem : objectCons ,
210
219
MinItems : attr .AttributeNestedType .MinItems ,
211
220
MaxItems : attr .AttributeNestedType .MaxItems ,
212
221
}
213
222
case tfjson .SchemaNestingModeMap :
214
- return schema.Map {
215
- Elem : convertJsonAttributesToObjectConstraint (attr .AttributeNestedType .Attributes ),
223
+ attrType = cty .Map (objType )
224
+ cons = schema.Map {
225
+ Elem : objectCons ,
216
226
MinItems : attr .AttributeNestedType .MinItems ,
217
227
MaxItems : attr .AttributeNestedType .MaxItems ,
218
228
}
229
+ default :
230
+ return nil
231
+ }
232
+
233
+ return schema.OneOf {
234
+ schema.AnyExpression {
235
+ OfType : attrType ,
236
+ SkipLiteralComplexTypes : true ,
237
+ },
238
+ cons ,
219
239
}
220
240
}
221
241
return nil
@@ -300,6 +320,41 @@ func convertJsonAttributesToObjectConstraint(attrs map[string]*tfjson.SchemaAttr
300
320
}
301
321
}
302
322
323
+ func convertJsonAttributesToCtyObject (attrs map [string ]* tfjson.SchemaAttribute ) cty.Type {
324
+ optional := make ([]string , 0 )
325
+ attributes := make (map [string ]cty.Type , 0 )
326
+
327
+ for name , attr := range attrs {
328
+ attributes [name ] = convertJsonAttributeToCtyType (attr )
329
+ if attr .Optional {
330
+ optional = append (optional , name )
331
+ }
332
+ }
333
+
334
+ return cty .ObjectWithOptionalAttrs (attributes , optional )
335
+ }
336
+
337
+ func convertJsonAttributeToCtyType (attr * tfjson.SchemaAttribute ) cty.Type {
338
+ if attr .AttributeType != cty .NilType {
339
+ return attr .AttributeType
340
+ }
341
+ if attr .AttributeNestedType != nil {
342
+ objType := convertJsonAttributesToCtyObject (attr .AttributeNestedType .Attributes )
343
+
344
+ switch attr .AttributeNestedType .NestingMode {
345
+ case tfjson .SchemaNestingModeSingle :
346
+ return objType
347
+ case tfjson .SchemaNestingModeList :
348
+ return cty .List (objType )
349
+ case tfjson .SchemaNestingModeSet :
350
+ return cty .Set (objType )
351
+ case tfjson .SchemaNestingModeMap :
352
+ return cty .Map (objType )
353
+ }
354
+ }
355
+ return cty .NilType
356
+ }
357
+
303
358
func markupContent (value string , kind tfjson.SchemaDescriptionKind ) lang.MarkupContent {
304
359
if value == "" {
305
360
return lang.MarkupContent {}
0 commit comments