@@ -22,6 +22,7 @@ package cloudstack
2222import (
2323 "fmt"
2424 "log"
25+ "regexp"
2526 "strconv"
2627 "strings"
2728
@@ -97,6 +98,14 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource {
9798 Set : schema .HashString ,
9899 },
99100
101+ "cidrlist" : {
102+ Type : schema .TypeSet ,
103+ Optional : true ,
104+ ForceNew : true ,
105+ Elem : & schema.Schema {Type : schema .TypeString },
106+ Set : schema .HashString ,
107+ },
108+
100109 "project" : {
101110 Type : schema .TypeString ,
102111 Optional : true ,
@@ -143,6 +152,16 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
143152 p .SetProtocol (protocol .(string ))
144153 }
145154
155+ // Set CIDR list
156+ if cidr , ok := d .GetOk ("cidrlist" ); ok {
157+ var cidrList []string
158+ for _ , id := range cidr .(* schema.Set ).List () {
159+ cidrList = append (cidrList , id .(string ))
160+ }
161+
162+ p .SetCidrlist (cidrList )
163+ }
164+
146165 // Set the ipaddress id
147166 p .SetPublicipid (d .Get ("ip_address_id" ).(string ))
148167
@@ -216,6 +235,12 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
216235 d .Set ("private_port" , private_port )
217236 d .Set ("protocol" , lb .Protocol )
218237
238+ // Only set cidr if user specified it to avoid spurious diffs
239+ delimiters := regexp .MustCompile (`\s*,\s*|\s+` )
240+ if _ , ok := d .GetOk ("cidrlist" ); ok {
241+ d .Set ("cidrlist" , delimiters .Split (lb .Cidrlist , - 1 ))
242+ }
243+
219244 // Only set network if user specified it to avoid spurious diffs
220245 if _ , ok := d .GetOk ("network_id" ); ok {
221246 d .Set ("network_id" , lb .Networkid )
0 commit comments