@@ -21,6 +21,7 @@ package cloudstack
2121
2222import (
2323 "fmt"
24+ "regexp"
2425 "testing"
2526
2627 "github.com/apache/cloudstack-go/v2/cloudstack"
@@ -67,6 +68,22 @@ func TestAccCloudStackIPAddress_vpc(t *testing.T) {
6768 })
6869}
6970
71+ func TestAccCloudStackIPAddress_vpcid_with_network_id(t *testing.T) {
72+
73+ regex := regexp.MustCompile("set only network_id or vpc_id")
74+ resource.Test(t, resource.TestCase{
75+ PreCheck: func() { testAccPreCheck(t) },
76+ Providers: testAccProviders,
77+ CheckDestroy: testAccCheckCloudStackIPAddressDestroy,
78+ Steps: []resource.TestStep{
79+ {
80+ ExpectError: regex,
81+ Config: testAccCloudStackIPAddress_vpcid_with_network_id,
82+ },
83+ },
84+ })
85+ }
86+
7087func testAccCheckCloudStackIPAddressExists(
7188 n string, ipaddr *cloudstack.PublicIpAddress) resource.TestCheckFunc {
7289 return func(s *terraform.State) error {
@@ -145,3 +162,25 @@ resource "cloudstack_ipaddress" "foo" {
145162 vpc_id = "${cloudstack_vpc.foo.id}"
146163 zone = "${cloudstack_vpc.foo.zone}"
147164}`
165+
166+ const testAccCloudStackIPAddress_vpcid_with_network_id = `
167+ resource "cloudstack_vpc" "foo" {
168+ name = "terraform-vpc"
169+ cidr = "10.0.0.0/8"
170+ vpc_offering = "Default VPC offering"
171+ zone = "Sandbox-simulator"
172+ }
173+
174+ resource "cloudstack_network" "foo" {
175+ name = "terraform-network"
176+ cidr = "10.1.1.0/24"
177+ network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
178+ source_nat_ip = true
179+ zone = "Sandbox-simulator"
180+ }
181+
182+ resource "cloudstack_ipaddress" "foo" {
183+ vpc_id = "${cloudstack_vpc.foo.id}"
184+ network_id = "${cloudstack_network.foo.id}"
185+ zone = "${cloudstack_vpc.foo.zone}"
186+ }`
0 commit comments