Skip to content

Commit

Permalink
Make pool on listener optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
alakae committed Oct 13, 2023
1 parent a35fe4d commit d5b9862
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions cloudscale/resource_cloudscale_load_balancer_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func getLoadBalancerListenerSchema(t SchemaType) map[string]*schema.Schema {
},
"pool_uuid": {
Type: schema.TypeString,
Required: t.isResource(),
Optional: t.isDataSource(),
Optional: true,
Computed: true,
ForceNew: true,
},
"pool_name": {
Expand Down Expand Up @@ -102,11 +102,14 @@ func resourceCloudscaleLoadBalancerListenerCreate(d *schema.ResourceData, meta a

opts := &cloudscale.LoadBalancerListenerRequest{
Name: d.Get("name").(string),
Pool: d.Get("pool_uuid").(string),
Protocol: d.Get("protocol").(string),
ProtocolPort: d.Get("protocol_port").(int),
}

if attr, ok := d.GetOk("pool_uuid"); ok {
opts.Pool = attr.(string)
}

if attr, ok := d.GetOk("timeout_client_data_ms"); ok {
opts.TimeoutClientDataMS = attr.(int)
}
Expand Down Expand Up @@ -148,9 +151,15 @@ func gatherLoadBalancerListenerResourceData(loadbalancerlistener *cloudscale.Loa
m["id"] = loadbalancerlistener.UUID
m["href"] = loadbalancerlistener.HREF
m["name"] = loadbalancerlistener.Name
m["pool_uuid"] = loadbalancerlistener.Pool.UUID
m["pool_name"] = loadbalancerlistener.Pool.Name
m["pool_href"] = loadbalancerlistener.Pool.HREF
if loadbalancerlistener.Pool != nil {
m["pool_uuid"] = loadbalancerlistener.Pool.UUID
m["pool_name"] = loadbalancerlistener.Pool.Name
m["pool_href"] = loadbalancerlistener.Pool.HREF
} else {
m["pool_uuid"] = nil
m["pool_name"] = nil
m["pool_href"] = nil
}
m["protocol"] = loadbalancerlistener.Protocol
m["protocol_port"] = loadbalancerlistener.ProtocolPort
m["timeout_client_data_ms"] = loadbalancerlistener.TimeoutClientDataMS
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/load_balancer_listener.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "cloudscale_load_balancer_listener" "lb1-listener" {
The following arguments are supported when creating new load balancer listener:

* `name` - (Required) Name of the new load balancer listener.
* `pool_uuid` - (Required) The pool of the listener.
* `pool_uuid` - (Optional/Required depending on protocol) The pool of the listener.
* `protocol` - (Required) The protocol used for receiving traffic. Options include `"tcp"`.
* `protocol_port` - (Required) The port on which traffic is received.
* `timeout_client_data_ms` - (Optional) Client inactivity timeout in milliseconds.
Expand Down

0 comments on commit d5b9862

Please sign in to comment.