Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom types have little effect when specified for attributes of nested objects #147

Open
1 task done
cysp opened this issue Jul 10, 2024 · 0 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@cysp
Copy link
Contributor

cysp commented Jul 10, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant