Skip to content

Commit

Permalink
Merge branch 'master' into fix/container-domain-404
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Nov 21, 2022
2 parents 9784454 + 65a248a commit c36c27e
Show file tree
Hide file tree
Showing 6 changed files with 3,040 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .markdownlinkcheck.json
Expand Up @@ -2,6 +2,9 @@
"ignorePatterns": [
{
"pattern": "^https://github.com/[^/]+/[^/]+/(issues|labels|pull)"
},
{
"pattern": "^https://failover-website.s3-website.fr-par.scw.cloud/"
}
],
"replacementPatterns": [
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/lb_backend.md
Expand Up @@ -57,6 +57,9 @@ The following arguments are supported:
- `timeout_server` - (Optional) Maximum server connection inactivity time. (e.g.: `1s`)
- `timeout_connect` - (Optional) Maximum initial server connection establishment time. (e.g.: `1s`)
- `timeout_tunnel` - (Optional) Maximum tunnel inactivity time. (e.g.: `1s`)
- `failover_host` - (Optional) Scaleway S3 bucket website to be served in case all backend servers are down.
~> **Note:** Only the host part of the Scaleway S3 bucket website is expected:
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/'.

### Health Check arguments

Expand Down
11 changes: 11 additions & 0 deletions scaleway/resource_lb_backend.go
Expand Up @@ -239,6 +239,14 @@ func resourceScalewayLbBackend() *schema.Resource {
Optional: true,
Description: "Modify what occurs when a backend server is marked down",
},
"failover_host": {
Type: schema.TypeString,
Optional: true,
Description: `Scaleway S3 bucket website to be served in case all backend servers are down
**NOTE** : Only the host part of the Scaleway S3 bucket website is expected.
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/'.`,
},
},
}
}
Expand Down Expand Up @@ -312,6 +320,7 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
TimeoutConnect: timeoutConnect,
TimeoutTunnel: timeoutTunnel,
OnMarkedDownAction: expandLbBackendMarkdownAction(d.Get("on_marked_down_action")),
FailoverHost: expandStringPtr(d.Get("failover_host")),
}

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

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

// deprecated
Expand Down
97 changes: 97 additions & 0 deletions scaleway/resource_lb_backend_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
Expand Down Expand Up @@ -188,6 +189,102 @@ func TestAccScalewayLbBackend_HealthCheck(t *testing.T) {
})
}

func TestAccScalewayLbBackend_WithFailoverHost(t *testing.T) {
rName := sdkacctest.RandomWithPrefix("tf-acc-test")
resourceName := "scaleway_object_bucket_website_configuration.test"

tt := NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: resource.ComposeTestCheckFunc(
testAccCheckScalewayLbBackendDestroy(tt),
testAccCheckScalewayObjectDestroy(tt),
testAccCheckScalewayObjectBucketDestroy(tt),
testAccCheckBucketWebsiteConfigurationDestroy(tt),
),
Steps: []resource.TestStep{
{
Config: `
resource scaleway_lb_ip ip01 {}
resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
}
resource scaleway_instance_ip ip01 {}
resource scaleway_lb_backend bkd01 {
lb_id = scaleway_lb.lb01.id
name = "bkd01"
forward_protocol = "http"
forward_port = 80
proxy_protocol = "none"
server_ips = [ scaleway_instance_ip.ip01.address ]
}
`,
Check: testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
},
{
Config: fmt.Sprintf(`
resource "scaleway_object_bucket" "test" {
name = %[1]q
acl = "public-read"
tags = {
TestName = "TestAccSCW_WebsiteConfig_basic"
}
}
resource scaleway_object "some_file" {
bucket = scaleway_object_bucket.test.name
key = "index.html"
file = "testfixture/index.html"
visibility = "public-read"
}
resource "scaleway_object_bucket_website_configuration" "test" {
bucket = scaleway_object_bucket.test.name
index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
}
resource scaleway_lb_ip ip01 {}
resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
}
resource scaleway_instance_ip ip01 {}
resource scaleway_lb_backend bkd01 {
lb_id = scaleway_lb.lb01.id
name = "bkd01"
forward_protocol = "http"
forward_port = 80
proxy_protocol = "none"
server_ips = [ scaleway_instance_ip.ip01.address ]
failover_host = scaleway_object_bucket_website_configuration.test.website_endpoint
}
`, rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckBucketWebsiteConfigurationExists(tt, resourceName),
testAccCheckScalewayLbBackendExists(tt, "scaleway_lb_backend.bkd01"),
resource.TestCheckResourceAttr(resourceName, "website_endpoint", rName+".s3-website.fr-par.scw.cloud"),
resource.TestCheckResourceAttrSet("scaleway_lb_backend.bkd01", "failover_host"),
),
ExpectNonEmptyPlan: !*UpdateCassettes,
},
},
})
}

func testAccCheckScalewayLbBackendExists(tt *TestTools, n string) resource.TestCheckFunc {
return func(state *terraform.State) error {
rs, ok := state.RootModule().Resources[n]
Expand Down

0 comments on commit c36c27e

Please sign in to comment.