Skip to content

Commit

Permalink
feat: add cidrlist parameter to loadbalancer rule
Browse files Browse the repository at this point in the history
fix: acceptance tests

style: remove comment
  • Loading branch information
chrxmvtik committed Dec 8, 2024
1 parent a653531 commit ee42bbf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cloudstack/resource_cloudstack_loadbalancer_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource {
Set: schema.HashString,
},

"cidrlist": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -143,6 +151,16 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
p.SetProtocol(protocol.(string))
}

// Set CIDR list
if cidr, ok := d.GetOk("cidrlist"); ok {
var cidrList []string
for _, id := range cidr.(*schema.Set).List() {
cidrList = append(cidrList, id.(string))
}

p.SetCidrlist(cidrList)
}

// Set the ipaddress id
p.SetPublicipid(d.Get("ip_address_id").(string))

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

// Only set cidr if user specified it to avoid spurious diffs
if _, ok := d.GetOk("cidrlist"); ok {
d.Set("cidrlist", strings.Split(lb.Cidrlist, ","))
}

// Only set network if user specified it to avoid spurious diffs
if _, ok := d.GetOk("network_id"); ok {
d.Set("network_id", lb.Networkid)
Expand Down
6 changes: 6 additions & 0 deletions cloudstack/resource_cloudstack_loadbalancer_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func TestAccCloudStackLoadBalancerRule_forceNew(t *testing.T) {
"cloudstack_loadbalancer_rule.foo", "private_port", "443"),
resource.TestCheckResourceAttr(
"cloudstack_loadbalancer_rule.foo", "protocol", "tcp-proxy"),
resource.TestCheckResourceAttr(
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "20.0.0.0/8"),
),
},
},
Expand Down Expand Up @@ -192,6 +194,8 @@ func TestAccCloudStackLoadBalancerRule_vpcUpdate(t *testing.T) {
"cloudstack_loadbalancer_rule.foo", "public_port", "443"),
resource.TestCheckResourceAttr(
"cloudstack_loadbalancer_rule.foo", "private_port", "443"),
resource.TestCheckResourceAttr(
"cloudstack_loadbalancer_rule.foo", "cidrlist.0", "20.0.0.0/8"),
),
},
},
Expand Down Expand Up @@ -357,6 +361,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
private_port = 443
protocol = "tcp-proxy"
member_ids = [cloudstack_instance.foobar1.id]
cidrlist = ["20.0.0.0/8"]
}`

const testAccCloudStackLoadBalancerRule_vpc = `
Expand Down Expand Up @@ -451,4 +456,5 @@ resource "cloudstack_loadbalancer_rule" "foo" {
public_port = 443
private_port = 443
member_ids = [cloudstack_instance.foobar1.id, cloudstack_instance.foobar2.id]
cidrlist = ["20.0.0.0/8"]
}`

0 comments on commit ee42bbf

Please sign in to comment.