Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cidrlist parameter to loadbalancer rule #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
}`
3 changes: 3 additions & 0 deletions website/docs/r/loadbalancer_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ resource "cloudstack_loadbalancer_rule" "default" {
private_port = 80
public_port = 80
member_ids = ["f8141e2f-4e7e-4c63-9362-986c908b7ea7"]
cidrlist = ["12.34.56.78/30","99.99.99.99/32"]
}
```

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

* `cidrlist` - (Optional) A CIDR list to allow access to the given ports.

* `project` - (Optional) The name or ID of the project to deploy this
instance to. Changing this forces a new resource to be created.

Expand Down