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

ImporterWrapper: Allocate a new Importer object (#1481) #1486

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions nsxt/removed_resource_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ func deleteWrapper(originalFunc schema.DeleteFunc, name string) schema.DeleteFun
}

func importerWrapper(originalImporter *schema.ResourceImporter, name string) *schema.ResourceImporter {
newImporter := new(schema.ResourceImporter)
Copy link
Collaborator

Choose a reason for hiding this comment

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

would it be more straightforward to return originalImporter here, and let the Read fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

that was the previous code.
Probably you meant do not wrapping the importer at all and let import fail at read?

wrappedFunc := func(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
if commonVersionCheck(m) {
return originalImporter.State(d, m)
stateFunc := originalImporter.State
return stateFunc(d, m)
}
log.Printf("[INFO] Failing import for resource %s: removed from NSX 9.0.0", name)
return nil, mpResourceRemovedError(name)
}
originalImporter.State = wrappedFunc
return originalImporter
newImporter.State = wrappedFunc
newImporter.StateContext = originalImporter.StateContext
return newImporter
}

func removedResourceWrapper(realResourceFunc resourceFunc, name string) *schema.Resource {
Expand Down
Loading