This is an automated email from the ASF dual-hosted git repository.
sureshanaparti pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git
The following commit(s) were added to refs/heads/main by this push:
new 140aaf2 Support requesting a specific IP address in
cloudstack_ipaddress (#311)
140aaf2 is described below
commit 140aaf2210a8d0dd63396ada8942d53581b8bce8
Author: Manoj Kumar <[email protected]>
AuthorDate: Mon Aug 17 14:49:52 2026 +0530
Support requesting a specific IP address in cloudstack_ipaddress (#311)
---
cloudstack/resource_cloudstack_ipaddress.go | 6 +++
cloudstack/resource_cloudstack_ipaddress_test.go | 61 ++++++++++++++++++++++++
website/docs/r/ipaddress.html.markdown | 5 ++
3 files changed, 72 insertions(+)
diff --git a/cloudstack/resource_cloudstack_ipaddress.go
b/cloudstack/resource_cloudstack_ipaddress.go
index 48e8813..28663e2 100644
--- a/cloudstack/resource_cloudstack_ipaddress.go
+++ b/cloudstack/resource_cloudstack_ipaddress.go
@@ -69,7 +69,9 @@ func resourceCloudStackIPAddress() *schema.Resource {
"ip_address": {
Type: schema.TypeString,
+ Optional: true,
Computed: true,
+ ForceNew: true,
},
"is_source_nat": {
@@ -148,6 +150,10 @@ func resourceCloudStackIPAddressCreate(d
*schema.ResourceData, meta interface{})
return err
}
+ if ipaddress, ok := d.GetOk("ip_address"); ok {
+ p.SetIpaddress(ipaddress.(string))
+ }
+
// Associate a new IP address
r, err := cs.Address.AssociateIpAddress(p)
if err != nil {
diff --git a/cloudstack/resource_cloudstack_ipaddress_test.go
b/cloudstack/resource_cloudstack_ipaddress_test.go
index da6a820..26606ee 100644
--- a/cloudstack/resource_cloudstack_ipaddress_test.go
+++ b/cloudstack/resource_cloudstack_ipaddress_test.go
@@ -68,6 +68,27 @@ func TestAccCloudStackIPAddress_vpc(t *testing.T) {
})
}
+func TestAccCloudStackIPAddress_specificIP(t *testing.T) {
+ var ipaddr cloudstack.PublicIpAddress
+
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ Providers: testAccProviders,
+ CheckDestroy: testAccCheckCloudStackIPAddressDestroy,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccCloudStackIPAddress_specificIP,
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckCloudStackIPAddressExists(
+ "cloudstack_ipaddress.foo",
&ipaddr),
+ resource.TestCheckResourceAttr(
+ "cloudstack_ipaddress.foo",
"ip_address", "10.2.2.11"),
+ ),
+ },
+ },
+ })
+}
+
func TestAccCloudStackIPAddress_vpcid_with_network_id(t *testing.T) {
regex := regexp.MustCompile("set only network_id or vpc_id")
@@ -222,6 +243,46 @@ resource "cloudstack_ipaddress" "foo" {
zone = cloudstack_vpc.foo.zone
}`
+const testAccCloudStackIPAddress_specificIP = `
+data "cloudstack_zone" "zone" {
+ filter {
+ name = "name"
+ value = "Sandbox-simulator"
+ }
+}
+
+data "cloudstack_physical_network" "pn" {
+ filter {
+ name = "zone_name"
+ value = "Sandbox-simulator"
+ }
+}
+
+resource "cloudstack_vlan_ip_range" "foo" {
+ physical_network_id = data.cloudstack_physical_network.pn.id
+ zone_id = data.cloudstack_zone.zone.id
+ for_virtual_network = true
+ vlan = "vlan://456"
+ gateway = "10.2.2.1"
+ netmask = "255.255.255.0"
+ start_ip = "10.2.2.10"
+ end_ip = "10.2.2.11"
+}
+
+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"
+}
+
+resource "cloudstack_ipaddress" "foo" {
+ network_id = cloudstack_network.foo.id
+ ip_address = cloudstack_vlan_ip_range.foo.end_ip
+}`
+
const testAccCloudStackIPAddress_vpcid_with_network_id = `
resource "cloudstack_vpc" "foo" {
name = "terraform-vpc"
diff --git a/website/docs/r/ipaddress.html.markdown
b/website/docs/r/ipaddress.html.markdown
index 8ec05c6..2a059eb 100644
--- a/website/docs/r/ipaddress.html.markdown
+++ b/website/docs/r/ipaddress.html.markdown
@@ -91,6 +91,11 @@ The following arguments are supported:
inherited from the VPC. If not specified and `network_id` is provided,
the project will be automatically inherited from the network.
+* `ip_address` - (Optional) A specific IP address to acquire from the available
+ pool (e.g. from a `cloudstack_vlan_ip_range` dedicated to an account). If
+ not set, CloudStack auto-selects the next free address. Changing this
+ forces a new resource to be created.
+
*NOTE: `network_id` and/or `zone` should have a value when `is_portable` is
`false`!*
*NOTE: Either `network_id` or `vpc_id` should have a value when `is_portable`
is `true`!*