Skip to content

Conversation

@manupedrozo
Copy link
Collaborator

Description

Removing usage of non-custom object, list, set & map types in autogen code now that we have custom versions for all of them.

  • Removed the previously introduced config flag use_custom_nested_types, all resources already use custom types.
  • Some refactoring in marshaling and testing code now that we have a clear picture of supported types.

I'll follow up with a PR to remove object types generation code (the withObjTypes flag is always set to false anyways).
As agreed offline, object types will not be needed since we took the custom types + reflection approach for conversion between TF schema and API json.

Link to any related issue(s): CLOUDP-352973

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved common functions used by custom types here.

@manupedrozo manupedrozo marked this pull request as ready for review October 31, 2025 14:59
@manupedrozo manupedrozo requested a review from a team as a code owner October 31, 2025 14:59
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

func getValueElementType[T attr.Value](ctx context.Context) attr.Type {
Copy link
Member

@lantoli lantoli Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: what is the difference between getValueElementType and getElementType attr.Type return, can you give an example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types that handle TF values (list, map, set) use getValueElementType (T is attr.Value).
Types that handle nested structs (object, nested_list, nested_map, nested_set) use getElementType (T is any), which requires traversal of the struct via reflection to generate the resulting type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, what about adding code comments with this or making the func names more explicit, e.g. getCollectionType and getNestedType

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one. Yes, I like that more. Changing in the followup PR.

fmt.Sprintf(`%T has usupported type: %s`, value.Interface(), valueType),
)}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: my preference is not to have so many empty lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌Removing empty line at 30 to follow the pattern. 0baa18b

Comment on lines +75 to +82
switch v := value.(type) {
case customtypes.ObjectValueInterface:
return resolveObjectAttr(ctx, v)
case customtypes.NestedListValueInterface:
return resolveNestedListAttr(ctx, v)
case customtypes.NestedMapValueInterface:
return resolveNestedMapAttr(ctx, v)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: Did we missing handling NestSet type here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to handle here since unmarshal does not generate unknowns (we do not merge sets with existing state).

withObjType: true,
goldenFileName: "primitive-attributes",
},
"Nested attributes": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Given custom type is how we now manage all nested attributes, would consider renaming the existing test Custom type attributes to Nested attributes and just ensuring we are capturing the existing nested attributes scenarios.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left the custom in the test name to avoid confusion since it covers both the "nested" and non "nested" custom types.
The existing scenarios are covered 👌
Merging to unblock next PR, if you insist on a different name I can change it in the next.

}

type SchemaOptions struct {
UseCustomNestedTypes *bool `yaml:"use_custom_nested_types"` // Tmp flag to disable custom nested types usage until typing is supported for all nested attributes. Defaults to true. - CLOUDP-352973
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to double check that we don't envision that we'll need this flag in some edge cases for new resources until we fix some unexpected issues

Copy link
Collaborator Author

@manupedrozo manupedrozo Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are removing all non-custom code so there is nothing to fall back to :D.
I am confident enough after getting complex resources like cluster_api & search_index_api working with custom types.

@manupedrozo manupedrozo merged commit ac88178 into master Nov 3, 2025
49 checks passed
@manupedrozo manupedrozo deleted the CLOUDP-352973-autogen-non-custom-types-cleanup branch November 3, 2025 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants