hashicorp / hashicorp/terraform-plugin-codegen-framework
Handle potential naming collisions
- Dominant language
- Go
- Stars
- 57
- Forks
- 29
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 1
Description
During the generation of data models there is the potential for the generated model names to conflict. There are at least 2 situations in which this could arise:
- Schemas that contain nested attributes
- Data sources, provider and resources that contain nested attributes
### Schemas that contain nested attributes
For example, in the case of schemas that contain nested attributes, we could have a situation such as the following in which two list_nested attributes within the intermediate representation contain an attribute with the same name
```json
{
"name": "list_nested_list_nested_bool_attribute",
"list_nested": {
"computed_optional_required": "computed",
"nested_object": {
"attributes": [
{
"name": "list_nested_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_attribute",
"list_nested": {
"computed_optional_required": "computed",
"nested_object": {
"attributes": [
{
"name": "list_attribute",
"list": {
"computed_optional_required": "computed",
"element_type": {
"string": {}
}
}
}
]
}
}
}
]
}
}
},
```
The generated models have a naming collision:
```go
type listNestedAttributeModel struct {
BoolAttribute types.Bool `tfsdk:"bool_attribute"`
}
type listNestedAttributeModel struct {
ListAttribute types.List `tfsdk:"list_attribute"`
}
```
### Data sources, provider and resources that contain nested attributes
An analogous situation could arise with data sources, provider and resources in which the schema contain nested attributes or blocks with the same names.
### Possible Solutions
- In the case of a single schema containing nested attributes, naming collisions such as the example illustrated above could be avoided by prepending each level of nested attribute with the name of the parent attribute.
- For potential naming collisions across data sources, provider and resources, one option would be to put each data source, provider and resource in a separate package.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.