Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cloudstack/resource_cloudstack_ipaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func resourceCloudStackIPAddress() *schema.Resource {
"network_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

Expand Down Expand Up @@ -99,6 +100,9 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
if networkid, ok := d.GetOk("network_id"); ok {
// Set the networkid
p.SetNetworkid(networkid.(string))
if vpcid, ok := d.GetOk("vpc_id"); ok && vpcid.(string) != "" {
return fmt.Errorf("set only network_id or vpc_id")
}
}

if vpcid, ok := d.GetOk("vpc_id"); ok {
Expand Down
39 changes: 39 additions & 0 deletions cloudstack/resource_cloudstack_ipaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package cloudstack

import (
"fmt"
"regexp"
"testing"

"github.com/apache/cloudstack-go/v2/cloudstack"
Expand Down Expand Up @@ -67,6 +68,22 @@ func TestAccCloudStackIPAddress_vpc(t *testing.T) {
})
}

func TestAccCloudStackIPAddress_vpcid_with_network_id(t *testing.T) {

regex := regexp.MustCompile("set only network_id or vpc_id")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudStackIPAddressDestroy,
Steps: []resource.TestStep{
{
ExpectError: regex,
Config: testAccCloudStackIPAddress_vpcid_with_network_id,
},
},
})
}

func testAccCheckCloudStackIPAddressExists(
n string, ipaddr *cloudstack.PublicIpAddress) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -145,3 +162,25 @@ resource "cloudstack_ipaddress" "foo" {
vpc_id = "${cloudstack_vpc.foo.id}"
zone = "${cloudstack_vpc.foo.zone}"
}`

const testAccCloudStackIPAddress_vpcid_with_network_id = `
resource "cloudstack_vpc" "foo" {
name = "terraform-vpc"
cidr = "10.0.0.0/8"
vpc_offering = "Default VPC offering"
zone = "Sandbox-simulator"
}

resource "cloudstack_network" "foo" {
name = "terraform-network"
cidr = "10.1.1.0/24"
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
source_nat_ip = true
zone = "Sandbox-simulator"
}

resource "cloudstack_ipaddress" "foo" {
vpc_id = "${cloudstack_vpc.foo.id}"
network_id = "${cloudstack_network.foo.id}"
zone = "${cloudstack_vpc.foo.zone}"
}`