Skip to content

Commit bfc6a1a

Browse files
committed
feat: add cidrlist parameter to loadbalancer rule
fix: acceptance tests style: remove comment docs: added cidrlist to loadbalancer_rule docs fix: adjust delimiter to cidr array
1 parent a653531 commit bfc6a1a

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

cloudstack/resource_cloudstack_loadbalancer_rule.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package cloudstack
2222
import (
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)

cloudstack/resource_cloudstack_loadbalancer_rule_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ func TestAccCloudStackLoadBalancerRule_forceNew(t *testing.T) {
129129
"cloudstack_loadbalancer_rule.foo", "private_port", "443"),
130130
resource.TestCheckResourceAttr(
131131
"cloudstack_loadbalancer_rule.foo", "protocol", "tcp-proxy"),
132+
resource.TestCheckResourceAttr(
133+
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "20.0.0.0/8"),
132134
),
133135
},
134136
},
@@ -192,6 +194,8 @@ func TestAccCloudStackLoadBalancerRule_vpcUpdate(t *testing.T) {
192194
"cloudstack_loadbalancer_rule.foo", "public_port", "443"),
193195
resource.TestCheckResourceAttr(
194196
"cloudstack_loadbalancer_rule.foo", "private_port", "443"),
197+
resource.TestCheckResourceAttr(
198+
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "20.0.0.0/8"),
195199
),
196200
},
197201
},
@@ -357,6 +361,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
357361
private_port = 443
358362
protocol = "tcp-proxy"
359363
member_ids = [cloudstack_instance.foobar1.id]
364+
cidrlist = ["20.0.0.0/8"]
360365
}`
361366

362367
const testAccCloudStackLoadBalancerRule_vpc = `
@@ -451,4 +456,5 @@ resource "cloudstack_loadbalancer_rule" "foo" {
451456
public_port = 443
452457
private_port = 443
453458
member_ids = [cloudstack_instance.foobar1.id, cloudstack_instance.foobar2.id]
459+
cidrlist = ["20.0.0.0/8"]
454460
}`

website/docs/r/loadbalancer_rule.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "cloudstack_loadbalancer_rule" "default" {
2121
private_port = 80
2222
public_port = 80
2323
member_ids = ["f8141e2f-4e7e-4c63-9362-986c908b7ea7"]
24+
cidrlist = ["12.34.56.78/30","99.99.99.99/32"]
2425
}
2526
```
2627

@@ -58,6 +59,8 @@ The following arguments are supported:
5859
* `member_ids` - (Required) List of instance IDs to assign to the load balancer
5960
rule. Changing this forces a new resource to be created.
6061

62+
* `cidrlist` - (Optional) A CIDR list to allow access to the given ports.
63+
6164
* `project` - (Optional) The name or ID of the project to deploy this
6265
instance to. Changing this forces a new resource to be created.
6366

0 commit comments

Comments
 (0)