Skip to content

Fix cloudstack_ipaddress delete silently succeeding on source-NAT IPs - #331

Open
sudo87 wants to merge 1 commit into
mainfrom
fix-ipaddress-sourcenat-delete
Open

Fix cloudstack_ipaddress delete silently succeeding on source-NAT IPs#331
sudo87 wants to merge 1 commit into
mainfrom
fix-ipaddress-sourcenat-delete

Conversation

@sudo87

@sudo87 sudo87 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@sudo87
sudo87 requested review from sureshanaparti and a lite review from Copilot August 28, 2026 09:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_nat conditional that skipped disassociation during delete.
  • Always calls DisassociateIpAddress and 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
}
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