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
3 changes: 2 additions & 1 deletion docs/data-sources/lb_routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ In addition to all arguments above, the following attributes are exported:
- `update_at` - The date on which the route was last updated (RFC 3339 format).
- `match_subdomains` - If true, all subdomains will match.
- `match_sni` - Server Name Indication TLS extension field from an incoming connection made via an SSL/TLS transport layer.
- `match_host_header` - Specifies the host of the server to which the request is being sent.
- `match_host_header` - Specifies the host of the server to which the request is being sent.
- `match_path_begin` - The value to match in the URL beginning path from an incoming request.
50 changes: 48 additions & 2 deletions docs/resources/lb_route.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,50 @@ resource "scaleway_lb_route" "rt01" {
}
```

### With path-begin matching for HTTP backends

```terraform
resource "scaleway_lb_ip" "ip" {}

resource "scaleway_lb" "lb" {
ip_id = scaleway_lb_ip.ip.id
name = "my-lb"
type = "lb-s"
}

resource "scaleway_lb_backend" "app" {
lb_id = scaleway_lb.lb.id
forward_protocol = "http"
forward_port = 80
proxy_protocol = "none"
}

resource "scaleway_lb_backend" "admin" {
lb_id = scaleway_lb.lb.id
forward_protocol = "http"
forward_port = 8080
proxy_protocol = "none"
}

resource "scaleway_lb_frontend" "frontend" {
lb_id = scaleway_lb.lb.id
backend_id = scaleway_lb_backend.app.id
inbound_port = 80
}

resource "scaleway_lb_route" "admin_route" {
frontend_id = scaleway_lb_frontend.frontend.id
backend_id = scaleway_lb_backend.admin.id
match_path_begin = "/admin"
}

resource "scaleway_lb_route" "default_route" {
frontend_id = scaleway_lb_frontend.frontend.id
backend_id = scaleway_lb_backend.app.id
match_path_begin = "/"
}
```

## Argument Reference

The following arguments are supported:
Expand All @@ -81,15 +125,17 @@ The following arguments are supported:
- `frontend_id` - (Required) The ID of the frontend the route is associated with.
- `match_subdomains` - (Default: `false`) If true, all subdomains will match.
- `match_sni` - The Server Name Indication (SNI) value to match. Value to match in the Server Name Indication TLS extension (SNI) field from an incoming connection made via an SSL/TLS transport layer.
Only one of `match_sni` and `match_host_header` should be specified.
Only one of `match_sni`, `match_host_header` and `match_path_begin` should be specified.

~> **Important:** This field should be set for routes on TCP Load Balancers.

- `match_host_header` - The HTTP host header to match. Value to match in the HTTP Host request header from an incoming connection.
Only one of `match_sni` and `match_host_header` should be specified.
Only one of `match_sni`, `match_host_header` and `match_path_begin` should be specified.

~> **Important:** This field should be set for routes on HTTP Load Balancers.

- `match_path_begin` - The value to match in the URL beginning path from an incoming request.
Only one of `match_sni`, `match_host_header` and `match_path_begin` should be specified.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the Load Balancer was created.

## Attributes Reference
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/nats-io/jwt/v2 v2.7.4
github.com/nats-io/nats.go v1.38.0
github.com/robfig/cron/v3 v3.0.1
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250424152954-b4babe8f214c
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250512145715-0fc65cc3636b
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.37.0
gopkg.in/dnaeon/go-vcr.v3 v3.2.0
Expand Down Expand Up @@ -135,9 +135,9 @@ require (
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.30.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ 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/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250424152954-b4babe8f214c h1:sjbNFhI3o5ecQuxLZv54Gm/YlqP55Ot5l7ShneWeNg8=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250424152954-b4babe8f214c/go.mod h1:w4o02EHpO0CBGy2nehzWRaFQKd62G9HIf+Q07PDaUcE=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250512145715-0fc65cc3636b h1:wzu3hPSNK2PPo7OXBzofeS5hOWqnVRP8xqIXom9ufoc=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250512145715-0fc65cc3636b/go.mod h1:qiGzapFyNPFwBBLJ+hTFykKSnU95n1zL64+o1ubmwf0=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down Expand Up @@ -401,8 +401,8 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -439,8 +439,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
13 changes: 11 additions & 2 deletions internal/services/lb/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ func ResourceRoute() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Description: "Server Name Indication TLS extension field from an incoming connection made via an SSL/TLS transport layer",
ConflictsWith: []string{"match_host_header"},
ConflictsWith: []string{"match_host_header", "match_path_begin"},
},
"match_host_header": {
Type: schema.TypeString,
Optional: true,
Description: "Specifies the host of the server to which the request is being sent",
ConflictsWith: []string{"match_sni"},
ConflictsWith: []string{"match_sni", "match_path_begin"},
},
"match_path_begin": {
Type: schema.TypeString,
Optional: true,
Description: "Value to match in the URL beginning path from an incoming request",
ConflictsWith: []string{"match_sni", "match_host_header"},
},
"match_subdomains": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -102,6 +108,7 @@ func resourceLbRouteCreate(ctx context.Context, d *schema.ResourceData, m interf
Match: &lbSDK.RouteMatch{
Sni: types.ExpandStringPtr(d.Get("match_sni")),
HostHeader: types.ExpandStringPtr(d.Get("match_host_header")),
PathBegin: types.ExpandStringPtr(d.Get("match_path_begin")),
MatchSubdomains: d.Get("match_subdomains").(bool),
},
}
Expand Down Expand Up @@ -140,6 +147,7 @@ func resourceLbRouteRead(ctx context.Context, d *schema.ResourceData, m interfac
_ = d.Set("backend_id", zonal.NewIDString(zone, route.BackendID))
_ = d.Set("match_sni", types.FlattenStringPtr(route.Match.Sni))
_ = d.Set("match_host_header", types.FlattenStringPtr(route.Match.HostHeader))
_ = d.Set("match_path_begin", types.FlattenStringPtr(route.Match.PathBegin))
_ = d.Set("match_subdomains", route.Match.MatchSubdomains)
_ = d.Set("created_at", types.FlattenTime(route.CreatedAt))
_ = d.Set("updated_at", types.FlattenTime(route.UpdatedAt))
Expand Down Expand Up @@ -169,6 +177,7 @@ func resourceLbRouteUpdate(ctx context.Context, d *schema.ResourceData, m interf
Match: &lbSDK.RouteMatch{
Sni: types.ExpandStringPtr(d.Get("match_sni")),
HostHeader: types.ExpandStringPtr(d.Get("match_host_header")),
PathBegin: types.ExpandStringPtr(d.Get("match_path_begin")),
MatchSubdomains: d.Get("match_subdomains").(bool),
},
}
Expand Down
44 changes: 44 additions & 0 deletions internal/services/lb/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,50 @@ func TestAccRoute_WithHostHeader(t *testing.T) {
})
}

func TestAccRoute_WithPathBegin(t *testing.T) {
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: isRouteDestroyed(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_lb_backend bkd01 {
lb_id = scaleway_lb.lb01.id
forward_protocol = "http"
forward_port = 80
proxy_protocol = "none"
}
resource scaleway_lb_frontend frt01 {
lb_id = scaleway_lb.lb01.id
backend_id = scaleway_lb_backend.bkd01.id
inbound_port = 80
}
resource scaleway_lb_route rt01 {
frontend_id = scaleway_lb_frontend.frt01.id
backend_id = scaleway_lb_backend.bkd01.id
match_path_begin = "/api"
}
`,
Check: resource.ComposeTestCheckFunc(
isRoutePresent(tt, "scaleway_lb_route.rt01"),
resource.TestCheckResourceAttr("scaleway_lb_route.rt01", "match_path_begin", "/api"),
resource.TestCheckResourceAttrSet("scaleway_lb_route.rt01", "created_at"),
resource.TestCheckResourceAttrSet("scaleway_lb_route.rt01", "updated_at"),
),
},
},
})
}

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