Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Add Load Balancer Rule protocol support (#22)
Browse files Browse the repository at this point in the history
* Add Load Balancer Rule protocol support

* PR feedback
  • Loading branch information
stuwil authored and Sander van Harmelen committed Nov 29, 2017
1 parent 278188a commit 881b4ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cloudstack/resource_cloudstack_loadbalancer_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func resourceCloudStackLoadBalancerRule() *schema.Resource {
ForceNew: true,
},

"protocol": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"member_ids": &schema.Schema{
Type: schema.TypeSet,
Required: true,
Expand Down Expand Up @@ -102,6 +109,11 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
p.SetNetworkid(networkid.(string))
}

// Set the protocol
if protocol, ok := d.GetOk("protocol"); ok {
p.SetProtocol(protocol.(string))
}

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

Expand All @@ -120,6 +132,7 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
d.SetPartial("algorithm")
d.SetPartial("private_port")
d.SetPartial("public_port")
d.SetPartial("protocol")

// Create a new parameter struct
ap := cs.LoadBalancer.NewAssignToLoadBalancerRuleParams(r.Id)
Expand Down Expand Up @@ -164,6 +177,7 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
d.Set("public_port", lb.Publicport)
d.Set("private_port", lb.Privateport)
d.Set("ip_address_id", lb.Publicipid)
d.Set("protocol", lb.Protocol)

// Only set network if user specified it to avoid spurious diffs
if _, ok := d.GetOk("network_id"); ok {
Expand Down
3 changes: 3 additions & 0 deletions cloudstack/resource_cloudstack_loadbalancer_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func TestAccCloudStackLoadBalancerRule_forceNew(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", "protocol", "tcp-proxy"),
),
},
},
Expand Down Expand Up @@ -307,6 +309,7 @@ resource "cloudstack_loadbalancer_rule" "foo" {
algorithm = "leastconn"
public_port = 443
private_port = 443
protocol = "tcp-proxy"
member_ids = ["${cloudstack_instance.foobar1.id}"]
}
`,
Expand Down
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 @@ -52,6 +52,9 @@ The following arguments are supported:
will be load balanced from. Changing this forces a new resource to be
created.

* `protocol` - (Optional) Load balancer protocol (tcp, udp, tcp-proxy).
Changing this forces a new resource to be created.

* `member_ids` - (Required) List of instance IDs to assign to the load balancer
rule. Changing this forces a new resource to be created.

Expand Down

0 comments on commit 881b4ac

Please sign in to comment.