Skip to content

Commit

Permalink
ImporterWrapper: Allocate a new Importer object (#1481)
Browse files Browse the repository at this point in the history
The wrapper function was updating the existing importer, but the replaced
function ended up having the same pointer as the wrapper function, meaning
that import would enter an infinite recursion loop.

Tested by doing import, read, update, and delete for
1) nsxt_logical_tier1_router
2) nsxt_ip_pool

Signed-off-by: Salvatore Orlando <[email protected]>
  • Loading branch information
salv-orlando committed Dec 18, 2024
1 parent 7a2c41a commit b3f333f
Showing 1 changed file with 6 additions and 3 deletions.
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)
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

0 comments on commit b3f333f

Please sign in to comment.