From 9c89f9c24e69b14845fa39a718f9456e8eff50bf Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Tue, 17 Dec 2024 16:42:19 +0100 Subject: [PATCH] ImporterWrapper: Allocate a new Importer object (#1481) 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 --- nsxt/removed_resource_wrapper.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nsxt/removed_resource_wrapper.go b/nsxt/removed_resource_wrapper.go index 7bd9d9de9..16b2bf5cb 100644 --- a/nsxt/removed_resource_wrapper.go +++ b/nsxt/removed_resource_wrapper.go @@ -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 {