Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/resources/lb_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ The following arguments are supported:
e.g. 'failover-website.s3-website.fr-par.scw.cloud' if your bucket website URL is 'https://failover-website.s3-website.fr-par.scw.cloud/'.
- `ssl_bridging` - (Default: `false`) Enables SSL between load balancer and backend servers.
- `ignore_ssl_server_verify` - (Default: `false`) Specifies whether the Load Balancer should check the backend server’s certificate before initiating a connection.
- `max_connections` - (Optional) Maximum number of connections allowed per backend server.
- `timeout_queue` - (Optional) Maximum time for a request to be left pending in queue when `max_connections` is reached. (e.g.: `1s`)

### Health Check arguments

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/nats-io/jwt/v2 v2.4.1
github.com/nats-io/nats.go v1.26.0
github.com/robfig/cron/v3 v3.0.1
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230619154501-6a12f2ddaa47
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230626132518-b0dfa1defaaf
github.com/stretchr/testify v1.8.4
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230619154501-6a12f2ddaa47 h1:eGARFgFhRDgxFF6QwimHe+MV21xhuPKLPNhJyML3JkA=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230619154501-6a12f2ddaa47/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230626132518-b0dfa1defaaf h1:df06kcC2caUTghLW6aTSyL3GUeM79BPvbtMyng187aE=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.17.0.20230626132518-b0dfa1defaaf/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down
39 changes: 39 additions & 0 deletions scaleway/resource_lb_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scaleway

import (
"context"
"math"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -274,6 +276,18 @@ E.g. 'failover-website.s3-website.fr-par.scw.cloud' if your bucket website URL i
Optional: true,
Default: false,
},
"max_connections": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, math.MaxInt32),
Description: "Maximum number of connections allowed per backend server",
},
"timeout_queue": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateDuration(),
Description: "Maximum time (in seconds) for a request to be left pending in queue when `max_connections` is reached",
},
},
}
}
Expand Down Expand Up @@ -352,6 +366,17 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
IgnoreSslServerVerify: expandBoolPtr(getBool(d, "ignore_ssl_server_verify")),
}

if maxConn, ok := d.GetOk("max_connections"); ok {
createReq.MaxConnections = expandInt32Ptr(maxConn)
}
if timeoutQueue, ok := d.GetOk("timeout_queue"); ok {
timeout, err := time.ParseDuration(timeoutQueue.(string))
if err != nil {
return diag.FromErr(err)
}
createReq.TimeoutQueue = &scw.Duration{Seconds: int64(timeout.Seconds())}
}

// deprecated attribute
createReq.SendProxyV2 = expandBoolPtr(getBool(d, "send_proxy_v2"))

Expand Down Expand Up @@ -416,6 +441,11 @@ func resourceScalewayLbBackendRead(ctx context.Context, d *schema.ResourceData,
_ = d.Set("failover_host", backend.FailoverHost)
_ = d.Set("ssl_bridging", flattenBoolPtr(backend.SslBridging))
_ = d.Set("ignore_ssl_server_verify", flattenBoolPtr(backend.IgnoreSslServerVerify))
_ = d.Set("max_connections", flattenInt32Ptr(backend.MaxConnections))

if backend.TimeoutQueue != nil {
_ = d.Set("timeout_queue", flattenDuration(backend.TimeoutQueue.ToTimeDuration()))
}

_, err = waitForLB(ctx, lbAPI, zone, backend.LB.ID, d.Timeout(schema.TimeoutRead))
if err != nil {
Expand Down Expand Up @@ -480,6 +510,15 @@ func resourceScalewayLbBackendUpdate(ctx context.Context, d *schema.ResourceData
FailoverHost: expandStringPtr(d.Get("failover_host")),
SslBridging: expandBoolPtr(getBool(d, "ssl_bridging")),
IgnoreSslServerVerify: expandBoolPtr(getBool(d, "ignore_ssl_server_verify")),
MaxConnections: expandInt32Ptr(d.Get("max_connections")),
}

if timeoutQueue, ok := d.GetOk("timeout_queue"); ok {
timeoutQueueParsed, err := time.ParseDuration(timeoutQueue.(string))
if err != nil {
return diag.FromErr(err)
}
req.TimeoutQueue = &scw.Duration{Seconds: int64(timeoutQueueParsed.Seconds())}
}

// deprecated
Expand Down
4 changes: 4 additions & 0 deletions scaleway/resource_lb_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
on_marked_down_action = "shutdown_sessions"
ssl_bridging = "true"
ignore_ssl_server_verify = "true"
max_connections = 42
timeout_queue = "4s"
}
`,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -99,6 +101,8 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "on_marked_down_action", "shutdown_sessions"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "ssl_bridging", "true"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "ignore_ssl_server_verify", "true"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "max_connections", "42"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "timeout_queue", "4s"),
),
},
},
Expand Down
Loading