Skip to content

Support requesting a specific IP address in cloudstack_ipaddress - #311

Open
sudo87 wants to merge 2 commits into
mainfrom
specifyIpAddress
Open

Support requesting a specific IP address in cloudstack_ipaddress#311
sudo87 wants to merge 2 commits into
mainfrom
specifyIpAddress

Conversation

@sudo87

@sudo87 sudo87 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

cloudstack_ipaddress currently always lets CloudStack auto-select the next
free IP — there's no way to request a specific address. This blocks a common
pattern: an operator dedicates an intranet VLAN/IP range to an account, and
the tenant needs to acquire one particular address from it (e.g. because
firewall rules, DNS, or routing on the corporate side are already provisioned
for that exact IP).

The CloudStack API (associateIpAddress) already accepts an optional
ipaddress parameter; the provider never called it.

Fixes #291

Changes

  • ip_address changes from Computed-only to Optional + Computed + ForceNew.
    There's no CloudStack API to change an IP association in place, so a change
    to ip_address correctly triggers destroy+recreate.
  • resourceCloudStackIPAddressCreate passes the value through to
    AssociateIpAddressParams.SetIpaddress when set.
  • No changes to Read/Delete — the allocated address was already read back
    from the API response.
  • New acceptance test, TestAccCloudStackIPAddress_specificIP, requesting a
    specific address from a dedicated cloudstack_vlan_ip_range so the
    assertion is deterministic (the shared default pool can't guarantee a given
    address is free).
  • Documented the new argument in website/docs/r/ipaddress.html.markdown.

Backward compatibility

Since ip_address was Computed-only before this change, no existing
configuration could have set it — Terraform rejects a config value for a
Computed-only attribute at validate time. The schema change is purely
additive; existing state with ip_address populated shows no diff.

Testing

Verified against a simulator

  • All pre-existing cloudstack_ipaddress acceptance tests pass unchanged
    (_basic, _vpc, _vpcid_with_network_id).
  • New _specificIP test passes.
  • Downstream consumers unaffected: data_source_cloudstack_ipaddress,
    cloudstack_loadbalancer_rule (all 5 variants), cloudstack_static_nat.
  • Idempotent: terraform plan/apply with ip_address set and unchanged
    produces no diff and performs no actions; same when ip_address is
    omitted from config against existing state.
  • Requesting an address already in use, or one outside any configured range,
    both fail clearly with CloudStack API error 533: Insufficient address capacity — no CloudStack-side ambiguity to handle.
  • Changing ip_address correctly triggers ForceNew, scoped to only the
    cloudstack_ipaddress resource (the associated network is untouched).
  • Manually verified (not yet covered by the automated test):
    vpc_id + ip_address, and is_portable = true + ip_address — both work
    correctly and are idempotent.

@sudo87
sudo87 requested review from vishesh92 and a lite review from Copilot and removed request for Copilot August 12, 2026 06:48

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

This PR adds support for requesting a specific public IP address in the cloudstack_ipaddress Terraform resource by exposing ip_address as a configurable argument and passing it through to CloudStack’s associateIpAddress API.

Changes:

  • Updated the cloudstack_ipaddress schema to make ip_address Optional + Computed + ForceNew.
  • Updated resource create logic to call AssociateIpAddressParams.SetIpaddress(...) when ip_address is provided.
  • Added documentation and a new acceptance test covering the new argument.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
cloudstack/resource_cloudstack_ipaddress.go Exposes ip_address as an optional ForceNew argument and forwards it to the CloudStack API on create.
cloudstack/resource_cloudstack_ipaddress_test.go Adds an acceptance test intended to verify requesting a specific IP address.
website/docs/r/ipaddress.html.markdown Documents the new ip_address argument and its ForceNew behavior.
Suppressed comments (2)

cloudstack/resource_cloudstack_ipaddress_test.go:211

  • To make TestAccCloudStackIPAddress_specificIP validate the new ip_address behavior, the dedicated VLAN range should include at least two addresses so CloudStack's default auto-allocation would likely choose a different IP than the one requested.
  end_ip               = "10.2.2.10"

cloudstack/resource_cloudstack_ipaddress_test.go:225

  • This should request the non-default address from the dedicated VLAN range (e.g. the range's end_ip) so the test exercises the ip_address request path rather than succeeding due to auto-selection.
  ip_address = cloudstack_vlan_ip_range.foo.start_ip

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cloudstack/resource_cloudstack_ipaddress_test.go Outdated
Copilot AI review requested due to automatic review settings August 12, 2026 10:06

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

cloudstack/resource_cloudstack_ipaddress_test.go:221

  • In the new acceptance test, cloudstack_network.foo sets source_nat_ip = true. That triggers an extra associateIpAddress during network creation, which can consume one of the IPs from the dedicated cloudstack_vlan_ip_range (and it does not depend on that range), making the test potentially flaky/non-deterministic. For this test, omit source_nat_ip so the only allocation is the cloudstack_ipaddress requesting the specific address.
resource "cloudstack_network" "foo" {
  name = "terraform-network"
  display_text = "terraform-network"
  cidr = "10.1.1.0/24"
  network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
  source_nat_ip = true
  zone = "Sandbox-simulator"

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.

Support requesting a specific IP address

2 participants