Skip to content

Fix orphaned NSX allocation on IP realization failure - #2303

Open
ksamoray wants to merge 1 commit into
vmware:masterfrom
ksamoray:fix/ip-address-allocation-realization-cleanup
Open

Fix orphaned NSX allocation on IP realization failure#2303
ksamoray wants to merge 1 commit into
vmware:masterfrom
ksamoray:fix/ip-address-allocation-realization-cleanup

Conversation

@ksamoray

@ksamoray ksamoray commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resourceNsxtPolicyIPAddressAllocationCreate waits for realization when allocation_ip is unset, and on failure tried to clean up the already-created NSX object via resourceNsxtPolicyIPAddressAllocationDelete(d, m). That function reads d.Id(), but the ID is only set on success — so on failure the cleanup silently no-op'd on an empty ID, leaking the IP allocation on NSX Manager with no corresponding Terraform state.
  • Fix: temporarily set d.SetId(id) so the real delete path (including its cache invalidation) can be reused for cleanup, then clear the ID again before returning the original error so Create still correctly reports nothing was created.

Test plan

  • go build ./... and go vet ./...
  • New unit tests in utgomock_resource_nsxt_policy_ip_address_allocation_test.go cover both failure paths (realization query error, and realized response missing the allocation_ip attribute), asserting cleanup actually deletes the NSX object and d.Id() ends up empty
  • go test -tags unittest ./nsxt/... passes for this resource

🤖 Generated with Claude Code

@ksamoray
ksamoray requested a review from a team August 27, 2026 08:58
@ksamoray

Copy link
Copy Markdown
Contributor Author

/test-all

@salv-orlando salv-orlando left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ksamoray
ksamoray force-pushed the fix/ip-address-allocation-realization-cleanup branch from da8672d to 9163c2e Compare September 8, 2026 11:13
@ksamoray

ksamoray commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

/test-all

1 similar comment
@ksamoray

ksamoray commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

/test-all

When allocation_ip is unset and realization fails, Create tried to clean
up via resourceNsxtPolicyIPAddressAllocationDelete before d.SetId() had
ever been called, so the delete silently no-op'd on an empty ID and the
allocation was leaked on NSX Manager with no Terraform state pointing to
it. Set the ID temporarily so the real delete path (including cache
invalidation) runs, then clear it again so Create still reports failure.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@ksamoray
ksamoray force-pushed the fix/ip-address-allocation-realization-cleanup branch from 9163c2e to aec1aa1 Compare September 8, 2026 16:15
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.

2 participants