Skip to content

Conversation

@manupedrozo
Copy link
Collaborator

Description

Description

Adding a custom Map terraform type for autogen usage following the work done at #3830 which added a custom NestedMap type.

The new customtypes.Map type is used for Terraform attr types, e.g. types.String.

Also:

  • Fixed a panic that occurred when unmarshaling zero-initiated nested attributes.
  • Enabled custom types for remaining resources: cluster_api & stream_instance_api.

Custom TF types docs: https://developer.hashicorp.com/terraform/plugin/framework/handling-data/types/custom

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

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

@manupedrozo manupedrozo marked this pull request as ready for review October 31, 2025 09:31
@manupedrozo manupedrozo requested a review from a team as a code owner October 31, 2025 09:31
target_states: ["DELETED"] # DELETED is a special state value when API returns 404 or empty object
version_header: application/vnd.atlas.2024-08-05+json
schema:
use_custom_nested_types: false
Copy link
Member

Choose a reason for hiding this comment

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

As these were the last usages of use_custom_nested_types, can we remove it from config_model.go? Ok if preference for separate PR, just want to make sure we remember removing and its associated usage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will be removed in the cleanup task yes CLOUDP-352973

}

func (v ObjectValue[T]) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
if v.ObjectValue.Equal(basetypes.ObjectValue{}) {
Copy link
Member

Choose a reason for hiding this comment

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

q: Is there a reason why this implementation deviates from other implementations which check for null?

if v.ElementType(ctx) == nil {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unlike other types, which just return the underlying elementType, the basetypes.ObjectValue.AttributeTypes() implementation creates and returns a map:

// AttributeTypes returns a copy of the mapping of attribute types for the Object.
func (o ObjectValue) AttributeTypes(_ context.Context) map[string]attr.Type {
	// Ensure callers cannot mutate the internal attribute types
	result := make(map[string]attr.Type, len(o.attributeTypes))

	for name, typ := range o.attributeTypes {
		result[name] = typ
	}

	return result
}

At which point, its better to compare against a zero-value.

@manupedrozo manupedrozo merged commit acffdf8 into master Oct 31, 2025
55 checks passed
@manupedrozo manupedrozo deleted the CLOUDP-353171-autogen-custom-map branch October 31, 2025 10:12
lantoli added a commit that referenced this pull request Oct 31, 2025
* master:
  Add support for typed maps in autogen (#3833)
  Add support for typed nested maps in autogen (#3830)
  doc: Clarify known limitation associated to creation of duplicate entries in `project_ip_access_list` (#3823)
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.

3 participants