-
Notifications
You must be signed in to change notification settings - Fork 27
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 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: cysp/terraform-plugin-codegen-framework-nested-custom-types@1a59ffe
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:
main...cysp:terraform-plugin-codegen-framework:custom-nested-object-attribute-types
… which results in this change in the reproduction example linked above: cysp/terraform-plugin-codegen-framework-nested-custom-types@main...custom-nested-object-attribute-types
Additional Information
No response
Code of Conduct
- I agree to follow this project's Code of Conduct