Open
Description
During the generation of data models, there can be a significant number of models that are generated for nested attributes and/or nested blocks.
For example, using the following intermediate representation (IR):
{
"datasources": [
{
"name": "datasource",
"schema": {
"attributes": [
{
"name": "list_nested_list_nested_bool_attribute",
"list_nested": {
"computed_optional_required": "computed",
"nested_object": {
"attributes": [
{
"name": "list_nested_bool_attribute",
"list_nested": {
"computed_optional_required": "computed",
"nested_object": {
"attributes": [
{
"name": "bool_attribute",
"bool": {
"computed_optional_required": "computed"
}
}
]
}
}
}
]
}
}
},
{
"name": "list_nested_list_nested_list_attribute",
"list_nested": {
"computed_optional_required": "computed",
"nested_object": {
"attributes": [
{
"name": "list_nested_list_attribute",
"list_nested": {
"computed_optional_required": "computed",
"nested_object": {
"attributes": [
{
"name": "list_attribute",
"list": {
"computed_optional_required": "computed",
"element_type": {
"string": {}
}
}
}
]
}
}
}
]
}
}
}
]
}
}
],
"provider": {
"name": "provider"
}
}
Results in the generation of the following models:
type datasourceModel struct {
ListNestedListNestedBoolAttribute types.List `tfsdk:"list_nested_list_nested_bool_attribute"`
ListNestedListNestedListAttribute types.List `tfsdk:"list_nested_list_nested_list_attribute"`
}
type listNestedListNestedBoolAttributeModel struct {
ListNestedBoolAttribute types.List `tfsdk:"list_nested_bool_attribute"`
}
type listNestedBoolAttributeModel struct {
BoolAttribute types.Bool `tfsdk:"bool_attribute"`
}
type listNestedListNestedListAttributeModel struct {
ListNestedListAttribute types.List `tfsdk:"list_nested_list_attribute"`
}
type listNestedListAttributeModel struct {
ListAttribute types.List `tfsdk:"list_attribute"`
}
Within other providers, for instance TLS, comments have been added to the models to make it more clear which nested model "belongs" to which model struct field.
In this instance, autogenerates comments indicating the relationships between the models would look something like the following:
type datasourceModel struct {
ListNestedListNestedBoolAttribute types.List `tfsdk:"list_nested_list_nested_bool_attribute"` //< listNestedListNestedBoolAttributeModel
ListNestedListNestedListAttribute types.List `tfsdk:"list_nested_list_nested_list_attribute"` //< listNestedListNestedListAttributeModel
}
type listNestedListNestedBoolAttributeModel struct {
ListNestedBoolAttribute types.List `tfsdk:"list_nested_bool_attribute"` // < listNestedBoolAttributeModel
}
type listNestedBoolAttributeModel struct {
BoolAttribute types.Bool `tfsdk:"bool_attribute"`
}
type listNestedListNestedListAttributeModel struct {
ListNestedListAttribute types.List `tfsdk:"list_nested_list_attribute"` // < listNestedListAttributeModel
}
type listNestedListAttributeModel struct {
ListAttribute types.List `tfsdk:"list_attribute"`
}
We may want to consider adding these comments to help with the navigation between and association of models and nested models.
Metadata
Metadata
Assignees
Labels
No labels