diff --git a/cloudstack/resource_cloudstack_network.go b/cloudstack/resource_cloudstack_network.go index e7329f82..4daf029e 100644 --- a/cloudstack/resource_cloudstack_network.go +++ b/cloudstack/resource_cloudstack_network.go @@ -74,7 +74,7 @@ func resourceCloudStackNetwork() *schema.Resource { "cidr": { Type: schema.TypeString, - Required: true, + Optional: true, ForceNew: true, }, @@ -190,23 +190,25 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e return err } - m, err := parseCIDR(d, no.Specifyipranges) - if err != nil { - return err - } + if _, ok := d.GetOk("cidr"); ok { + m, err := parseCIDR(d, no.Specifyipranges) + if err != nil { + return err + } - // Set the needed IP config - p.SetGateway(m["gateway"]) - p.SetNetmask(m["netmask"]) + // Set the needed IP config + p.SetGateway(m["gateway"]) + p.SetNetmask(m["netmask"]) - // Only set the start IP if we have one - if startip, ok := m["startip"]; ok { - p.SetStartip(startip) - } + // Only set the start IP if we have one + if startip, ok := m["startip"]; ok { + p.SetStartip(startip) + } - // Only set the end IP if we have one - if endip, ok := m["endip"]; ok { - p.SetEndip(endip) + // Only set the end IP if we have one + if endip, ok := m["endip"]; ok { + p.SetEndip(endip) + } } // Set the network domain if we have one diff --git a/cloudstack/resource_cloudstack_network_test.go b/cloudstack/resource_cloudstack_network_test.go index 0b650ace..c706e020 100644 --- a/cloudstack/resource_cloudstack_network_test.go +++ b/cloudstack/resource_cloudstack_network_test.go @@ -377,3 +377,30 @@ resource "cloudstack_network" "foo" { acl_id = cloudstack_network_acl.bar.id zone = cloudstack_vpc.foo.zone }` + +func TestAccCloudStackNetwork_l2NoCidr(t *testing.T) { + var network cloudstack.Network + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCloudStackNetworkDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudStackNetwork_l2NoCidr, + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudStackNetworkExists( + "cloudstack_network.l2", &network), + ), + }, + }, + }) +} + +const testAccCloudStackNetwork_l2NoCidr = ` +resource "cloudstack_network" "l2" { + name = "terraform-l2-network" + display_text = "terraform-l2-network" + network_offering = "DefaultL2NetworkOffering" + zone = "Sandbox-simulator" +}`