Skip to content

Commit e4537b1

Browse files
committed
feat: add cidrlist parameter to loadbalancer rule
1 parent a653531 commit e4537b1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cloudstack/resource_cloudstack_loadbalancer_rule.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource {
9797
Set: schema.HashString,
9898
},
9999

100+
"cidrlist": {
101+
Type: schema.TypeSet,
102+
Optional: true,
103+
Computed: 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,
@@ -142,6 +151,13 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
142151
if protocol, ok := d.GetOk("protocol"); ok {
143152
p.SetProtocol(protocol.(string))
144153
}
154+
//TEST
155+
var cidrList []string
156+
for _, id := range d.Get("cidrlist").(*schema.Set).List() {
157+
cidrList = append(cidrList, id.(string))
158+
}
159+
160+
p.SetCidrlist(cidrList)
145161

146162
// Set the ipaddress id
147163
p.SetPublicipid(d.Get("ip_address_id").(string))
@@ -216,6 +232,11 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
216232
d.Set("private_port", private_port)
217233
d.Set("protocol", lb.Protocol)
218234

235+
// Only set cidr if user specified it to avoid spurious diffs
236+
if _, ok := d.GetOk("cidrlist"); ok {
237+
d.Set("cidrlist", strings.Split(lb.Cidrlist, ","))
238+
}
239+
219240
// Only set network if user specified it to avoid spurious diffs
220241
if _, ok := d.GetOk("network_id"); ok {
221242
d.Set("network_id", lb.Networkid)

cloudstack/resource_cloudstack_loadbalancer_rule_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ func TestAccCloudStackLoadBalancerRule_forceNew(t *testing.T) {
112112
"cloudstack_loadbalancer_rule.foo", "public_port", "80"),
113113
resource.TestCheckResourceAttr(
114114
"cloudstack_loadbalancer_rule.foo", "private_port", "80"),
115+
resource.TestCheckResourceAttr(
116+
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "10.0.0.0/8"),
115117
),
116118
},
117119

@@ -129,6 +131,8 @@ func TestAccCloudStackLoadBalancerRule_forceNew(t *testing.T) {
129131
"cloudstack_loadbalancer_rule.foo", "private_port", "443"),
130132
resource.TestCheckResourceAttr(
131133
"cloudstack_loadbalancer_rule.foo", "protocol", "tcp-proxy"),
134+
resource.TestCheckResourceAttr(
135+
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "20.0.0.0/8"),
132136
),
133137
},
134138
},
@@ -177,6 +181,8 @@ func TestAccCloudStackLoadBalancerRule_vpcUpdate(t *testing.T) {
177181
"cloudstack_loadbalancer_rule.foo", "public_port", "80"),
178182
resource.TestCheckResourceAttr(
179183
"cloudstack_loadbalancer_rule.foo", "private_port", "80"),
184+
resource.TestCheckResourceAttr(
185+
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "10.0.0.0/8"),
180186
),
181187
},
182188

@@ -192,6 +198,10 @@ func TestAccCloudStackLoadBalancerRule_vpcUpdate(t *testing.T) {
192198
"cloudstack_loadbalancer_rule.foo", "public_port", "443"),
193199
resource.TestCheckResourceAttr(
194200
"cloudstack_loadbalancer_rule.foo", "private_port", "443"),
201+
resource.TestCheckResourceAttr(
202+
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "20.0.0.0/8"),
203+
resource.TestCheckResourceAttr(
204+
"cloudstack_loadbalancer_rule.foo", "cidrlist.1", "30.0.0.0/8"),
195205
),
196206
},
197207
},
@@ -290,6 +300,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
290300
public_port = 80
291301
private_port = 80
292302
member_ids = [cloudstack_instance.foobar1.id]
303+
cidrlist = ["10.0.0.0/8"]
293304
}`
294305

295306
const testAccCloudStackLoadBalancerRule_update = `
@@ -323,6 +334,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
323334
public_port = 80
324335
private_port = 80
325336
member_ids = [cloudstack_instance.foobar1.id]
337+
cidrlist = ["10.0.0.0/8"]
326338
}`
327339

328340
const testAccCloudStackLoadBalancerRule_forcenew = `
@@ -357,6 +369,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
357369
private_port = 443
358370
protocol = "tcp-proxy"
359371
member_ids = [cloudstack_instance.foobar1.id]
372+
cidrlist = ["20.0.0.0/8"]
360373
}`
361374

362375
const testAccCloudStackLoadBalancerRule_vpc = `
@@ -399,6 +412,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
399412
public_port = 80
400413
private_port = 80
401414
member_ids = [cloudstack_instance.foobar1.id]
415+
cidrlist = ["10.0.0.0/8"]
402416
}`
403417

404418
const testAccCloudStackLoadBalancerRule_vpc_update = `
@@ -451,4 +465,5 @@ resource "cloudstack_loadbalancer_rule" "foo" {
451465
public_port = 443
452466
private_port = 443
453467
member_ids = [cloudstack_instance.foobar1.id, cloudstack_instance.foobar2.id]
468+
cidrlist = ["20.0.0.0/8"]
454469
}`

0 commit comments

Comments
 (0)