hashicorp / hashicorp/terraform-plugin-codegen-framework
Custom types have little effect when specified for attributes of nested objects
- Dominant language
- Go
- Stars
- 57
- Forks
- 29
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 1
Description
### Use Cases or Problem Statement
I'm implementing a provider containing a resource that has an attribute modelled as a list of nested objects, where an attribute of the nested object is a JSON value. Unfortunately the upstream API for this resource occasionally returns this JSON field with keys reordered, so I would like to model that nested field using [`jsontypes`](https://github.com/hashicorp/terraform-plugin-framework-jsontypes) to apply semantic equality and avoid meaningless diffs.
I tried specifying a custom type in the specification for this nested attribute but that seems to only affect the generated schema, not the model structs generated for nested objects. This is evident in the lack of semantic equality behaviour for these nested attributes.
The difference in generated code is visible in this commit: https://github.com/cysp/terraform-plugin-codegen-framework-nested-custom-types/commit/1a59ffe8946463d088f56bb34513d2fc6bb0e2f7
Note that the top-level json field's type in `ResourceModel` is affected by the custom type but the model fields for nested objects show no change.
### Proposal
Hand-editing the generated model structs to replace `basetypes.String{Type,Value}` with the custom `jsontypes` representations gives the expected behaviour, and looking at the code generator it looks like there's a fairly simple (but widespread) change to make to respect custom type specifications.
This change to the code generator implements custom types for string attributes in nested contexts:
https://github.com/hashicorp/terraform-plugin-codegen-framework/compare/main...cysp:terraform-plugin-codegen-framework:custom-nested-object-attribute-types
… which results in this change in the reproduction example linked above: https://github.com/cysp/terraform-plugin-codegen-framework-nested-custom-types/compare/main...custom-nested-object-attribute-types
### Additional Information
_No response_
### Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.