Fix cloudstack_ipaddress delete silently succeeding on source-NAT IPs - #331
Open
sudo87 wants to merge 1 commit into
Open
Fix cloudstack_ipaddress delete silently succeeding on source-NAT IPs#331sudo87 wants to merge 1 commit into
sudo87 wants to merge 1 commit into
Conversation
resourceCloudStackIPAddressDelete skipped the disassociate call entirely when is_source_nat was true and returned nil, so Terraform reported the resource destroyed while CloudStack left the IP allocated. Always call DisassociateIpAddress and propagate whatever CloudStack returns instead of swallowing it, matching every other error path in this file. Verified against a live 4.23.0.0 lab: against an implemented network with a running virtual router, CloudStack now correctly rejects the destroy (error 530, IP still in use for source NAT) instead of Terraform falsely reporting success; against a network that was never implemented, the disassociate genuinely succeeds and is now reported accurately.
Contributor
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Fixes Terraform incorrectly reporting CloudStack IP address resources as deleted when the IP is a source-NAT IP by always issuing the CloudStack disassociate call and returning CloudStack’s response.
Changes:
- Removed the
is_source_natconditional that skipped disassociation during delete. - Always calls
DisassociateIpAddressand returns the resulting error (except for the existing “already gone” special-case).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return nil | ||
| } | ||
|
|
||
| return fmt.Errorf("Error disassociating IP address %s: %s", d.Id(), err) |
Comment on lines
+286
to
291
| // This is a very poor way to be told the ID does no longer exist :( | ||
| if strings.Contains(err.Error(), fmt.Sprintf( | ||
| "Invalid parameter id value=%s due to incorrect long value format, "+ | ||
| "or entity does not exist", d.Id())) { | ||
| return nil | ||
| } |
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.
resourceCloudStackIPAddressDelete skipped the disassociate call entirely when is_source_nat was true and returned nil, so Terraform reported the resource destroyed while CloudStack left the IP allocated. Always call DisassociateIpAddress and propagate whatever CloudStack returns instead of swallowing it, matching every other error path in this file.
Verified against a live 4.23.0.0 lab: against an implemented network with a running virtual router, CloudStack now correctly rejects the destroy (error 530, IP still in use for source NAT) instead of Terraform falsely reporting success; against a network that was never implemented, the disassociate genuinely succeeds and is now reported accurately.