Fix orphaned NSX allocation on IP realization failure - #2303
Open
ksamoray wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
/test-all |
ksamoray
force-pushed
the
fix/ip-address-allocation-realization-cleanup
branch
from
September 8, 2026 11:13
da8672d to
9163c2e
Compare
Contributor
Author
|
/test-all |
1 similar comment
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
force-pushed
the
fix/ip-address-allocation-realization-cleanup
branch
from
September 8, 2026 16:15
9163c2e to
aec1aa1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resourceNsxtPolicyIPAddressAllocationCreatewaits for realization whenallocation_ipis unset, and on failure tried to clean up the already-created NSX object viaresourceNsxtPolicyIPAddressAllocationDelete(d, m). That function readsd.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.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 soCreatestill correctly reports nothing was created.Test plan
go build ./...andgo vet ./...utgomock_resource_nsxt_policy_ip_address_allocation_test.gocover both failure paths (realization query error, and realized response missing theallocation_ipattribute), asserting cleanup actually deletes the NSX object andd.Id()ends up emptygo test -tags unittest ./nsxt/...passes for this resource🤖 Generated with Claude Code