Skip to content

Commit d155cfc

Browse files
committed
added dest_cidr_list option to resource_cloudstack_egress_firewall and updated doc page accordingly
1 parent 16915b6 commit d155cfc

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

cloudstack/resource_cloudstack_egress_firewall.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ func resourceCloudStackEgressFirewall() *schema.Resource {
7070
Set: schema.HashString,
7171
},
7272

73+
"dest_cidr_list": {
74+
Type: schema.TypeSet,
75+
Optional: true,
76+
Elem: &schema.Schema{Type: schema.TypeString},
77+
Set: schema.HashString,
78+
},
79+
7380
"protocol": {
7481
Type: schema.TypeString,
7582
Required: true,
@@ -194,6 +201,15 @@ func createEgressFirewallRule(d *schema.ResourceData, meta interface{}, rule map
194201
p.SetCidrlist(cidrList)
195202
}
196203

204+
// Set the destination CIDR list
205+
var destcidrList []string
206+
if rs := rule["cidr_list"].(*schema.Set); rs.Len() > 0 {
207+
for _, cidr := range rule["dest_cidr_list"].(*schema.Set).List() {
208+
destcidrList = append(destcidrList, cidr.(string))
209+
}
210+
p.SetDestcidrlist(destcidrList)
211+
}
212+
197213
// If the protocol is ICMP set the needed ICMP parameters
198214
if rule["protocol"].(string) == "icmp" {
199215
p.SetIcmptype(rule["icmp_type"].(int))
@@ -319,11 +335,18 @@ func resourceCloudStackEgressFirewallRead(d *schema.ResourceData, meta interface
319335
cidrs.Add(cidr)
320336
}
321337

338+
// Create a set with all destination CIDR's
339+
destcidrs := &schema.Set{F: schema.HashString}
340+
for _, cidr := range strings.Split(r.Destcidrlist, ",") {
341+
destcidrs.Add(cidr)
342+
}
343+
322344
// Update the values
323345
rule["protocol"] = r.Protocol
324346
rule["icmp_type"] = r.Icmptype
325347
rule["icmp_code"] = r.Icmpcode
326348
rule["cidr_list"] = cidrs
349+
rule["dest_cidr_list"] = destcidrs
327350
rules.Add(rule)
328351
}
329352

@@ -357,9 +380,16 @@ func resourceCloudStackEgressFirewallRead(d *schema.ResourceData, meta interface
357380
cidrs.Add(cidr)
358381
}
359382

383+
// Create a set with all destination CIDR's
384+
destcidrs := &schema.Set{F: schema.HashString}
385+
for _, cidr := range strings.Split(r.Destcidrlist, ",") {
386+
destcidrs.Add(cidr)
387+
}
388+
360389
// Update the values
361390
rule["protocol"] = r.Protocol
362391
rule["cidr_list"] = cidrs
392+
rule["dest_cidr_list"] = destcidrs
363393
ports.Add(port)
364394
}
365395

website/docs/r/egress_firewall.html.markdown

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ resource "cloudstack_egress_firewall" "default" {
1717
network_id = "6eb22f91-7454-4107-89f4-36afcdf33021"
1818
1919
rule {
20-
cidr_list = ["10.0.0.0/8"]
21-
protocol = "tcp"
22-
ports = ["80", "1000-2000"]
20+
cidr_list = ["10.1.0.0/16"]
21+
dest_cidr_list = ["10.2.0.0/16"]
22+
protocol = "tcp"
23+
ports = ["80", "1000-2000"]
2324
}
2425
}
2526
```
@@ -43,7 +44,9 @@ The following arguments are supported:
4344

4445
The `rule` block supports:
4546

46-
* `cidr_list` - (Required) A CIDR list to allow access to the given ports.
47+
* `cidr_list` - (Required) the cidr list to forward traffic from.
48+
49+
* `dest_cidr_list` - (Optional) the cidr list to forward traffic to.
4750

4851
* `protocol` - (Required) The name of the protocol to allow. Valid options are:
4952
`tcp`, `udp` and `icmp`.

0 commit comments

Comments
 (0)