Skip to content

Commit ee42bbf

Browse files
committed
feat: add cidrlist parameter to loadbalancer rule
fix: acceptance tests style: remove comment
1 parent a653531 commit ee42bbf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

cloudstack/resource_cloudstack_loadbalancer_rule.go

+23
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource {
9797
Set: schema.HashString,
9898
},
9999

100+
"cidrlist": {
101+
Type: schema.TypeSet,
102+
Optional: true,
103+
ForceNew: true,
104+
Elem: &schema.Schema{Type: schema.TypeString},
105+
Set: schema.HashString,
106+
},
107+
100108
"project": {
101109
Type: schema.TypeString,
102110
Optional: true,
@@ -143,6 +151,16 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
143151
p.SetProtocol(protocol.(string))
144152
}
145153

154+
// Set CIDR list
155+
if cidr, ok := d.GetOk("cidrlist"); ok {
156+
var cidrList []string
157+
for _, id := range cidr.(*schema.Set).List() {
158+
cidrList = append(cidrList, id.(string))
159+
}
160+
161+
p.SetCidrlist(cidrList)
162+
}
163+
146164
// Set the ipaddress id
147165
p.SetPublicipid(d.Get("ip_address_id").(string))
148166

@@ -216,6 +234,11 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
216234
d.Set("private_port", private_port)
217235
d.Set("protocol", lb.Protocol)
218236

237+
// Only set cidr if user specified it to avoid spurious diffs
238+
if _, ok := d.GetOk("cidrlist"); ok {
239+
d.Set("cidrlist", strings.Split(lb.Cidrlist, ","))
240+
}
241+
219242
// Only set network if user specified it to avoid spurious diffs
220243
if _, ok := d.GetOk("network_id"); ok {
221244
d.Set("network_id", lb.Networkid)

cloudstack/resource_cloudstack_loadbalancer_rule_test.go

+6
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
}`

0 commit comments

Comments
 (0)