@@ -58,7 +58,7 @@ func resourceCloudStackEgressFirewall() *schema.Resource {
58
58
Schema : map [string ]* schema.Schema {
59
59
"cidr_list" : {
60
60
Type : schema .TypeSet ,
61
- Required : true ,
61
+ Optional : true ,
62
62
Elem : & schema.Schema {Type : schema .TypeString },
63
63
Set : schema .HashString ,
64
64
},
@@ -180,10 +180,12 @@ func createEgressFirewallRule(d *schema.ResourceData, meta interface{}, rule map
180
180
181
181
// Set the CIDR list
182
182
var cidrList []string
183
- for _ , cidr := range rule ["cidr_list" ].(* schema.Set ).List () {
184
- cidrList = append (cidrList , cidr .(string ))
183
+ if rs := rule ["cidr_list" ].(* schema.Set ); rs .Len () > 0 {
184
+ for _ , cidr := range rule ["cidr_list" ].(* schema.Set ).List () {
185
+ cidrList = append (cidrList , cidr .(string ))
186
+ }
187
+ p .SetCidrlist (cidrList )
185
188
}
186
- p .SetCidrlist (cidrList )
187
189
188
190
// If the protocol is ICMP set the needed ICMP parameters
189
191
if rule ["protocol" ].(string ) == "icmp" {
@@ -198,8 +200,8 @@ func createEgressFirewallRule(d *schema.ResourceData, meta interface{}, rule map
198
200
rule ["uuids" ] = uuids
199
201
}
200
202
201
- // If protocol is not ICMP, loop through all ports
202
- if rule ["protocol" ].(string ) != "icmp" {
203
+ // If protocol is not ICMP and not ALL , loop through all ports
204
+ if rule ["protocol" ].(string ) != "icmp" && strings . ToLower ( rule [ "protocol" ].( string )) != "all" {
203
205
if ps := rule ["ports" ].(* schema.Set ); ps .Len () > 0 {
204
206
205
207
// Create an empty schema.Set to hold all processed ports
@@ -244,6 +246,14 @@ func createEgressFirewallRule(d *schema.ResourceData, meta interface{}, rule map
244
246
}
245
247
}
246
248
249
+ if strings .ToLower (rule ["protocol" ].(string )) == "all" {
250
+ r , err := cs .Firewall .CreateEgressFirewallRule (p )
251
+ if err != nil {
252
+ return err
253
+ }
254
+ uuids ["all" ] = r .Id
255
+ rule ["uuids" ] = uuids
256
+ }
247
257
return nil
248
258
}
249
259
@@ -306,7 +316,7 @@ func resourceCloudStackEgressFirewallRead(d *schema.ResourceData, meta interface
306
316
}
307
317
308
318
// If protocol is not ICMP, loop through all ports
309
- if rule ["protocol" ].(string ) != "icmp" {
319
+ if rule ["protocol" ].(string ) != "icmp" && strings . ToLower ( rule [ "protocol" ].( string )) != "all" {
310
320
if ps := rule ["ports" ].(* schema.Set ); ps .Len () > 0 {
311
321
312
322
// Create an empty schema.Set to hold all ports
@@ -348,6 +358,35 @@ func resourceCloudStackEgressFirewallRead(d *schema.ResourceData, meta interface
348
358
}
349
359
}
350
360
}
361
+ if strings .ToLower (rule ["protocol" ].(string )) == "all" {
362
+ id , ok := uuids ["all" ]
363
+ if ! ok {
364
+ continue
365
+ }
366
+
367
+ // Get the rule
368
+ r , ok := ruleMap [id .(string )]
369
+ if ! ok {
370
+ delete (uuids , "all" )
371
+ continue
372
+ }
373
+
374
+ // Delete the known rule so only unknown rules remain in the ruleMap
375
+ delete (ruleMap , id .(string ))
376
+
377
+ // Create a set with all CIDR's
378
+ if _ , ok := rule ["cidr_list" ]; ok {
379
+ cidrs := & schema.Set {F : schema .HashString }
380
+ for _ , cidr := range strings .Split (r .Cidrlist , "," ) {
381
+ cidrs .Add (cidr )
382
+ }
383
+ rule ["cidr_list" ] = cidrs
384
+ }
385
+
386
+ // Update the values
387
+ rule ["protocol" ] = r .Protocol
388
+ rules .Add (rule )
389
+ }
351
390
}
352
391
}
353
392
@@ -532,9 +571,9 @@ func verifyEgressFirewallParams(d *schema.ResourceData) error {
532
571
533
572
func verifyEgressFirewallRuleParams (d * schema.ResourceData , rule map [string ]interface {}) error {
534
573
protocol := rule ["protocol" ].(string )
535
- if protocol != "tcp" && protocol != "udp" && protocol != "icmp" {
574
+ if strings . ToLower ( protocol ) != "all" && protocol != "tcp" && protocol != "udp" && protocol != "icmp" {
536
575
return fmt .Errorf (
537
- "%q is not a valid protocol. Valid options are 'tcp', 'udp' and 'icmp'" , protocol )
576
+ "%q is not a valid protocol. Valid options are 'ALL', ' tcp', 'udp' and 'icmp'" , protocol )
538
577
}
539
578
540
579
if protocol == "icmp" {
@@ -546,7 +585,7 @@ func verifyEgressFirewallRuleParams(d *schema.ResourceData, rule map[string]inte
546
585
return fmt .Errorf (
547
586
"Parameter icmp_code is a required parameter when using protocol 'icmp'" )
548
587
}
549
- } else {
588
+ } else if strings . ToLower ( protocol ) != "all" {
550
589
if ports , ok := rule ["ports" ].(* schema.Set ); ok {
551
590
for _ , port := range ports .List () {
552
591
m := splitPorts .FindStringSubmatch (port .(string ))
@@ -559,6 +598,11 @@ func verifyEgressFirewallRuleParams(d *schema.ResourceData, rule map[string]inte
559
598
return fmt .Errorf (
560
599
"Parameter ports is a required parameter when *not* using protocol 'icmp'" )
561
600
}
601
+ } else if strings .ToLower (protocol ) == "all" {
602
+ if ports , _ := rule ["ports" ].(* schema.Set ); ports .Len () > 0 {
603
+ return fmt .Errorf (
604
+ "Parameter ports is not required when using protocol 'ALL'" )
605
+ }
562
606
}
563
607
564
608
return nil
0 commit comments