Support requesting a specific IP address in cloudstack_ipaddress - #311
Support requesting a specific IP address in cloudstack_ipaddress#311sudo87 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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_ipaddressschema to makeip_addressOptional + Computed + ForceNew. - Updated resource create logic to call
AssociateIpAddressParams.SetIpaddress(...)whenip_addressis 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_specificIPvalidate the newip_addressbehavior, 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 theip_addressrequest 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.
There was a problem hiding this comment.
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.foosetssource_nat_ip = true. That triggers an extraassociateIpAddressduring network creation, which can consume one of the IPs from the dedicatedcloudstack_vlan_ip_range(and it does not depend on that range), making the test potentially flaky/non-deterministic. For this test, omitsource_nat_ipso the only allocation is thecloudstack_ipaddressrequesting 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"
Summary
cloudstack_ipaddresscurrently always lets CloudStack auto-select the nextfree 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 optionalipaddressparameter; the provider never called it.Fixes #291
Changes
ip_addresschanges fromComputed-only toOptional + Computed + ForceNew.There's no CloudStack API to change an IP association in place, so a change
to
ip_addresscorrectly triggers destroy+recreate.resourceCloudStackIPAddressCreatepasses the value through toAssociateIpAddressParams.SetIpaddresswhen set.Read/Delete— the allocated address was already read backfrom the API response.
TestAccCloudStackIPAddress_specificIP, requesting aspecific address from a dedicated
cloudstack_vlan_ip_rangeso theassertion is deterministic (the shared default pool can't guarantee a given
address is free).
website/docs/r/ipaddress.html.markdown.Backward compatibility
Since
ip_addresswasComputed-only before this change, no existingconfiguration could have set it — Terraform rejects a config value for a
Computed-only attribute at validate time. The schema change is purelyadditive; existing state with
ip_addresspopulated shows no diff.Testing
Verified against a simulator
cloudstack_ipaddressacceptance tests pass unchanged(
_basic,_vpc,_vpcid_with_network_id)._specificIPtest passes.data_source_cloudstack_ipaddress,cloudstack_loadbalancer_rule(all 5 variants),cloudstack_static_nat.terraform plan/applywithip_addressset and unchangedproduces no diff and performs no actions; same when
ip_addressisomitted from config against existing state.
both fail clearly with
CloudStack API error 533: Insufficient address capacity— no CloudStack-side ambiguity to handle.ip_addresscorrectly triggersForceNew, scoped to only thecloudstack_ipaddressresource (the associated network is untouched).vpc_id+ip_address, andis_portable = true+ip_address— both workcorrectly and are idempotent.