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
36 changes: 18 additions & 18 deletions docs/resources/lb_backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ e.g. 'failover-website.s3-website.fr-par.scw.cloud' if your bucket website URL i
Backends use Health Check to test if a backend server is ready to receive requests.
You may use one of the following health check types: `TCP`, `HTTP` or `HTTPS`. (Default: `TCP`)

- `health_check_timeout` - (Default: `30s`) Timeout before we consider a HC request failed.
- `health_check_delay` - (Default: `60s`) Interval between two HC requests.
- `health_check_port` - (Default: `forward_port`) Port the HC requests will be send to.
- `health_check_max_retries` - (Default: `2`) Number of allowed failed HC requests before the backend server is marked down.
- `health_check_tcp` - (Optional) This block enable TCP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
- `health_check_http` - (Optional) This block enable HTTP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
- `uri` - (Required) The HTTP endpoint URL to call for HC requests.
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
- `code` - (Default: `200`) The expected HTTP status code.
- `host_header` - (Optional) The HTTP host header to use for HC requests.
- `health_check_https` - (Optional) This block enable HTTPS health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
- `uri` - (Required) The HTTPS endpoint URL to call for HC requests.
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
- `code` - (Default: `200`) The expected HTTP status code.
- `host_header` - (Optional) The HTTP host header to use for HC requests.
- `sni` - (Optional) The SNI to use for HC requests over SSL.
- `on_marked_down_action` - (Default: `none`) Modify what occurs when a backend server is marked down. Possible values are: `none` and `shutdown_sessions`.

- `health_check_timeout` - (Default: `30s`) Timeout before we consider a HC request failed.
- `health_check_delay` - (Default: `60s`) Interval between two HC requests.
- `health_check_port` - (Default: `forward_port`) Port the HC requests will be send to.
- `health_check_max_retries` - (Default: `2`) Number of allowed failed HC requests before the backend server is marked down.
- `health_check_tcp` - (Optional) This block enable TCP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
- `health_check_http` - (Optional) This block enable HTTP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
- `uri` - (Required) The HTTP endpoint URL to call for HC requests.
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
- `code` - (Default: `200`) The expected HTTP status code.
- `host_header` - (Optional) The HTTP host header to use for HC requests.
- `health_check_https` - (Optional) This block enable HTTPS health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
- `uri` - (Required) The HTTPS endpoint URL to call for HC requests.
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
- `code` - (Default: `200`) The expected HTTP status code.
- `host_header` - (Optional) The HTTP host header to use for HC requests.
- `sni` - (Optional) The SNI to use for HC requests over SSL.
- `on_marked_down_action` - (Default: `none`) Modify what occurs when a backend server is marked down. Possible values are: `none` and `shutdown_sessions`.
- `health_check_transient_delay` - (Default: `0.5s`) The time to wait between two consecutive health checks when a backend server is in a transient state (going UP or DOWN).

## Attributes Reference

Expand Down
39 changes: 30 additions & 9 deletions scaleway/resource_lb_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ func resourceScalewayLbBackend() *schema.Resource {
},
},
},
"health_check_transient_delay": {
Type: schema.TypeString,
Optional: true,
Default: "0.5s",
ValidateFunc: validateDuration(),
DiffSuppressFunc: diffSuppressFuncDuration,
Description: "Time to wait between two consecutive health checks when a backend server is in a transient state (going UP or DOWN)",
},
"on_marked_down_action": {
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
Expand Down Expand Up @@ -286,11 +294,12 @@ E.g. 'failover-website.s3-website.fr-par.scw.cloud' if your bucket website URL i
Description: "Maximum number of connections allowed per backend server",
},
"timeout_queue": {
Type: schema.TypeString,
Optional: true,
Default: "0s",
ValidateFunc: validateDuration(),
Description: "Maximum time (in seconds) for a request to be left pending in queue when `max_connections` is reached",
Type: schema.TypeString,
Optional: true,
Default: "0s",
ValidateFunc: validateDuration(),
DiffSuppressFunc: diffSuppressFuncDuration,
Description: "Maximum time (in seconds) for a request to be left pending in queue when `max_connections` is reached",
},
"redispatch_attempt_count": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -399,6 +408,13 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
if maxRetries, ok := d.GetOk("max_retries"); ok {
createReq.MaxRetries = expandInt32Ptr(maxRetries)
}
if healthCheckTransientDelay, ok := d.GetOk("health_check_transient_delay"); ok {
timeout, err := time.ParseDuration(healthCheckTransientDelay.(string))
if err != nil {
return diag.FromErr(err)
}
createReq.HealthCheck.TransientCheckDelay = &scw.Duration{Seconds: int64(timeout.Seconds()), Nanos: int32(timeout.Nanoseconds())}
}

// deprecated attribute
createReq.SendProxyV2 = expandBoolPtr(getBool(d, "send_proxy_v2"))
Expand Down Expand Up @@ -467,10 +483,8 @@ func resourceScalewayLbBackendRead(ctx context.Context, d *schema.ResourceData,
_ = d.Set("max_connections", flattenInt32Ptr(backend.MaxConnections))
_ = d.Set("redispatch_attempt_count", flattenInt32Ptr(backend.RedispatchAttemptCount))
_ = d.Set("max_retries", flattenInt32Ptr(backend.MaxRetries))

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

_, err = waitForLB(ctx, lbAPI, zone, backend.LB.ID, d.Timeout(schema.TimeoutRead))
if err != nil {
Expand Down Expand Up @@ -575,6 +589,13 @@ func resourceScalewayLbBackendUpdate(ctx context.Context, d *schema.ResourceData
HTTPConfig: expandLbHCHTTP(d.Get("health_check_http")),
HTTPSConfig: expandLbHCHTTPS(d.Get("health_check_https")),
}
if healthCheckTransientDelay, ok := d.GetOk("health_check_transient_delay"); ok {
timeout, err := time.ParseDuration(healthCheckTransientDelay.(string))
if err != nil {
return diag.FromErr(err)
}
updateHCRequest.TransientCheckDelay = &scw.Duration{Seconds: int64(timeout.Seconds()), Nanos: int32(timeout.Nanoseconds())}
}

// As this is the default behaviour if no other HC type are present we enable TCP
if updateHCRequest.HTTPConfig == nil && updateHCRequest.HTTPSConfig == nil {
Expand Down
3 changes: 3 additions & 0 deletions scaleway/resource_lb_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "ignore_ssl_server_verify", "false"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "redispatch_attempt_count", "0"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "max_retries", "3"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_transient_delay", "500ms"),
),
},
{
Expand Down Expand Up @@ -94,6 +95,7 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
timeout_queue = "4s"
redispatch_attempt_count = 1
max_retries = 6
health_check_transient_delay = "0.2s"
}
`,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -114,6 +116,7 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "timeout_queue", "4s"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "redispatch_attempt_count", "1"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "max_retries", "6"),
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_transient_delay", "200ms"),
),
},
},
Expand Down
Loading