Skip to content

Commit 5725816

Browse files
committed
Make cidr optional for L2 network creation
1 parent 47439a1 commit 5725816

2 files changed

Lines changed: 44 additions & 15 deletions

File tree

cloudstack/resource_cloudstack_network.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func resourceCloudStackNetwork() *schema.Resource {
7474

7575
"cidr": {
7676
Type: schema.TypeString,
77-
Required: true,
77+
Optional: true,
7878
ForceNew: true,
7979
},
8080

@@ -190,23 +190,25 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e
190190
return err
191191
}
192192

193-
m, err := parseCIDR(d, no.Specifyipranges)
194-
if err != nil {
195-
return err
196-
}
193+
if _, ok := d.GetOk("cidr"); ok {
194+
m, err := parseCIDR(d, no.Specifyipranges)
195+
if err != nil {
196+
return err
197+
}
197198

198-
// Set the needed IP config
199-
p.SetGateway(m["gateway"])
200-
p.SetNetmask(m["netmask"])
199+
// Set the needed IP config
200+
p.SetGateway(m["gateway"])
201+
p.SetNetmask(m["netmask"])
201202

202-
// Only set the start IP if we have one
203-
if startip, ok := m["startip"]; ok {
204-
p.SetStartip(startip)
205-
}
203+
// Only set the start IP if we have one
204+
if startip, ok := m["startip"]; ok {
205+
p.SetStartip(startip)
206+
}
206207

207-
// Only set the end IP if we have one
208-
if endip, ok := m["endip"]; ok {
209-
p.SetEndip(endip)
208+
// Only set the end IP if we have one
209+
if endip, ok := m["endip"]; ok {
210+
p.SetEndip(endip)
211+
}
210212
}
211213

212214
// Set the network domain if we have one

cloudstack/resource_cloudstack_network_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,30 @@ resource "cloudstack_network" "foo" {
377377
acl_id = cloudstack_network_acl.bar.id
378378
zone = cloudstack_vpc.foo.zone
379379
}`
380+
381+
func TestAccCloudStackNetwork_l2NoCidr(t *testing.T) {
382+
var network cloudstack.Network
383+
384+
resource.Test(t, resource.TestCase{
385+
PreCheck: func() { testAccPreCheck(t) },
386+
Providers: testAccProviders,
387+
CheckDestroy: testAccCheckCloudStackNetworkDestroy,
388+
Steps: []resource.TestStep{
389+
{
390+
Config: testAccCloudStackNetwork_l2NoCidr,
391+
Check: resource.ComposeTestCheckFunc(
392+
testAccCheckCloudStackNetworkExists(
393+
"cloudstack_network.l2", &network),
394+
),
395+
},
396+
},
397+
})
398+
}
399+
400+
const testAccCloudStackNetwork_l2NoCidr = `
401+
resource "cloudstack_network" "l2" {
402+
name = "terraform-l2-network"
403+
display_text = "terraform-l2-network"
404+
network_offering = "DefaultL2NetworkOffering"
405+
zone = "Sandbox-simulator"
406+
}`

0 commit comments

Comments
 (0)