Skip to content

chore: Uses NewUnknownReplacements meant to replace schemafunc.CopyUnknowns logic and schemafunc.NewAttributeChanges #3192

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

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

EspenAlbert
Copy link
Collaborator

@EspenAlbert EspenAlbert commented Mar 21, 2025

Description

Adds NewUnknownReplacements meant to replace schemafunc.CopyUnknowns logic and schemafunc.NewAttributeChanges.

The new common logic replaces the need for reflect and instead uses Terraform's req.State.Raw.Diff(req.Config.Raw) to find changes.
It also comes with a simplified API where each individual field can be defined instead of having to go top-down.
Note: fields can be defined at any level, for example electable_specs or instance_size are both valid.
See #3218, #3223, #3236 for how the usage is for advanced_cluster

See also guide on adding a new attribute here

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

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

Base automatically changed from CLOUDP-307843_plan_modifier_test_support to master March 24, 2025 09:56
@EspenAlbert EspenAlbert marked this pull request as ready for review March 24, 2025 16:05
@EspenAlbert EspenAlbert requested a review from a team as a code owner March 24, 2025 16:05
@EspenAlbert EspenAlbert changed the title chore: Adds NewUnknownReplacements meant to replace schemafunc.CopyUnknowns logic and schemafunc.NewAttributeChanges chore: Uses NewUnknownReplacements meant to replace schemafunc.CopyUnknowns logic and schemafunc.NewAttributeChanges Mar 24, 2025
}

// ModifyPlan is the only method overridden in this test.
func (r *rs) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
Copy link
Member

Choose a reason for hiding this comment

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

as discussed offline, not sure about this test as it's very coupled to the implementation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Curious to hear what others think. Please react with 👍 if you find it useful or 👎 if it is just noisy/confusing

@EspenAlbert EspenAlbert marked this pull request as ready for review March 27, 2025 12:52
}

// AttributePath similar to the internal function in TPF, but simpler interface as argument and less logging
func AttributePath(ctx context.Context, tfType *tftypes.AttributePath, schema TPFSchema) (path.Path, diag.Diagnostics) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't gone deep, but it smells a lot we're copying internal methods. Also, what is the impact on the policy?

Copy link
Member

Choose a reason for hiding this comment

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

Did we get any additional information 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.

Good point. Waiting on reply.

Copy link
Collaborator

@oarbusi oarbusi left a comment

Choose a reason for hiding this comment

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

Very long PR 😅 overall LGMT


func readSrcStructValue[T any](ctx context.Context, src conversion.TPFSrc, p path.Path) *T {
var obj types.Object
if localDiags := src.GetAttribute(ctx, p, &obj); localDiags.HasError() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

localDiags not used/passed anywhere? Why is it handled differently than in readSrcStructValues?

Copy link
Collaborator Author

@EspenAlbert EspenAlbert Mar 28, 2025

Choose a reason for hiding this comment

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

Thanks for spotting this.
I'm not 100% sure all the cases where this might happen.
I think it is used in readSrcStructValues to use the conversion.TFModelList method, but I agree we should be consistent.
I'll investigate and update

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, choosing to remove the diags argument.
These errors should be spotted before production, but just to be sure, we log them instead of adding to "root" diagnostics. This avoids any risk of the user having a "stuck" resource due to plan modifier errors.

Copy link
Contributor

github-actions bot commented Apr 8, 2025

This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

@github-actions github-actions bot added the stale label Apr 8, 2025
@EspenAlbert EspenAlbert added the not_stale Not stale issue or PR label Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not_stale Not stale issue or PR stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants