Skip to content

Commit 65a248a

Browse files
yfodilremyleonequantumsheepCodelax
authored
feat(lb): add support for failoverhost (#1583)
Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: Nathanael Demacon <[email protected]> Co-authored-by: Jules Castéran <[email protected]>
1 parent cfc8bf5 commit 65a248a

File tree

6 files changed

+3040
-0
lines changed

6 files changed

+3040
-0
lines changed

.markdownlinkcheck.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"ignorePatterns": [
33
{
44
"pattern": "^https://github.com/[^/]+/[^/]+/(issues|labels|pull)"
5+
},
6+
{
7+
"pattern": "^https://failover-website.s3-website.fr-par.scw.cloud/"
58
}
69
],
710
"replacementPatterns": [

docs/resources/lb_backend.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ The following arguments are supported:
5757
- `timeout_server` - (Optional) Maximum server connection inactivity time. (e.g.: `1s`)
5858
- `timeout_connect` - (Optional) Maximum initial server connection establishment time. (e.g.: `1s`)
5959
- `timeout_tunnel` - (Optional) Maximum tunnel inactivity time. (e.g.: `1s`)
60+
- `failover_host` - (Optional) Scaleway S3 bucket website to be served in case all backend servers are down.
61+
~> **Note:** Only the host part of the Scaleway S3 bucket website is expected:
62+
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/'.
6063

6164
### Health Check arguments
6265

scaleway/resource_lb_backend.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ func resourceScalewayLbBackend() *schema.Resource {
239239
Optional: true,
240240
Description: "Modify what occurs when a backend server is marked down",
241241
},
242+
"failover_host": {
243+
Type: schema.TypeString,
244+
Optional: true,
245+
Description: `Scaleway S3 bucket website to be served in case all backend servers are down
246+
247+
**NOTE** : Only the host part of the Scaleway S3 bucket website is expected.
248+
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/'.`,
249+
},
242250
},
243251
}
244252
}
@@ -312,6 +320,7 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
312320
TimeoutConnect: timeoutConnect,
313321
TimeoutTunnel: timeoutTunnel,
314322
OnMarkedDownAction: expandLbBackendMarkdownAction(d.Get("on_marked_down_action")),
323+
FailoverHost: expandStringPtr(d.Get("failover_host")),
315324
}
316325

317326
// deprecated attribute
@@ -375,6 +384,7 @@ func resourceScalewayLbBackendRead(ctx context.Context, d *schema.ResourceData,
375384
_ = d.Set("health_check_http", flattenLbHCHTTP(backend.HealthCheck.HTTPConfig))
376385
_ = d.Set("health_check_https", flattenLbHCHTTPS(backend.HealthCheck.HTTPSConfig))
377386
_ = d.Set("send_proxy_v2", flattenBoolPtr(backend.SendProxyV2))
387+
_ = d.Set("failover_host", backend.FailoverHost)
378388

379389
_, err = waitForLB(ctx, lbAPI, zone, backend.LB.ID, d.Timeout(schema.TimeoutRead))
380390
if err != nil {
@@ -436,6 +446,7 @@ func resourceScalewayLbBackendUpdate(ctx context.Context, d *schema.ResourceData
436446
TimeoutConnect: timeoutConnect,
437447
TimeoutTunnel: timeoutTunnel,
438448
OnMarkedDownAction: expandLbBackendMarkdownAction(d.Get("on_marked_down_action")),
449+
FailoverHost: expandStringPtr(d.Get("failover_host")),
439450
}
440451

441452
// deprecated

scaleway/resource_lb_backend_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7+
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
910
lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
@@ -188,6 +189,102 @@ func TestAccScalewayLbBackend_HealthCheck(t *testing.T) {
188189
})
189190
}
190191

192+
func TestAccScalewayLbBackend_WithFailoverHost(t *testing.T) {
193+
rName := sdkacctest.RandomWithPrefix("tf-acc-test")
194+
resourceName := "scaleway_object_bucket_website_configuration.test"
195+
196+
tt := NewTestTools(t)
197+
defer tt.Cleanup()
198+
resource.ParallelTest(t, resource.TestCase{
199+
PreCheck: func() { testAccPreCheck(t) },
200+
ProviderFactories: tt.ProviderFactories,
201+
CheckDestroy: resource.ComposeTestCheckFunc(
202+
testAccCheckScalewayLbBackendDestroy(tt),
203+
testAccCheckScalewayObjectDestroy(tt),
204+
testAccCheckScalewayObjectBucketDestroy(tt),
205+
testAccCheckBucketWebsiteConfigurationDestroy(tt),
206+
),
207+
Steps: []resource.TestStep{
208+
{
209+
Config: `
210+
resource scaleway_lb_ip ip01 {}
211+
resource scaleway_lb lb01 {
212+
ip_id = scaleway_lb_ip.ip01.id
213+
name = "test-lb"
214+
type = "lb-s"
215+
}
216+
217+
resource scaleway_instance_ip ip01 {}
218+
219+
resource scaleway_lb_backend bkd01 {
220+
lb_id = scaleway_lb.lb01.id
221+
name = "bkd01"
222+
forward_protocol = "http"
223+
forward_port = 80
224+
proxy_protocol = "none"
225+
server_ips = [ scaleway_instance_ip.ip01.address ]
226+
}
227+
`,
228+
Check: testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
229+
},
230+
{
231+
Config: fmt.Sprintf(`
232+
resource "scaleway_object_bucket" "test" {
233+
name = %[1]q
234+
acl = "public-read"
235+
tags = {
236+
TestName = "TestAccSCW_WebsiteConfig_basic"
237+
}
238+
}
239+
240+
resource scaleway_object "some_file" {
241+
bucket = scaleway_object_bucket.test.name
242+
key = "index.html"
243+
file = "testfixture/index.html"
244+
visibility = "public-read"
245+
}
246+
247+
resource "scaleway_object_bucket_website_configuration" "test" {
248+
bucket = scaleway_object_bucket.test.name
249+
index_document {
250+
suffix = "index.html"
251+
}
252+
error_document {
253+
key = "error.html"
254+
}
255+
}
256+
257+
resource scaleway_lb_ip ip01 {}
258+
resource scaleway_lb lb01 {
259+
ip_id = scaleway_lb_ip.ip01.id
260+
name = "test-lb"
261+
type = "lb-s"
262+
}
263+
264+
resource scaleway_instance_ip ip01 {}
265+
266+
resource scaleway_lb_backend bkd01 {
267+
lb_id = scaleway_lb.lb01.id
268+
name = "bkd01"
269+
forward_protocol = "http"
270+
forward_port = 80
271+
proxy_protocol = "none"
272+
server_ips = [ scaleway_instance_ip.ip01.address ]
273+
failover_host = scaleway_object_bucket_website_configuration.test.website_endpoint
274+
}
275+
`, rName),
276+
Check: resource.ComposeTestCheckFunc(
277+
testAccCheckBucketWebsiteConfigurationExists(tt, resourceName),
278+
testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
279+
resource.TestCheckResourceAttr(resourceName, "website_endpoint", rName+".s3-website.fr-par.scw.cloud"),
280+
resource.TestCheckResourceAttrSet("scaleway_lb_backend.bkd01", "failover_host"),
281+
),
282+
ExpectNonEmptyPlan: !*UpdateCassettes,
283+
},
284+
},
285+
})
286+
}
287+
191288
func testAccCheckScalewayLbBackendExists(tt *TestTools, n string) resource.TestCheckFunc {
192289
return func(state *terraform.State) error {
193290
rs, ok := state.RootModule().Resources[n]

0 commit comments

Comments
 (0)