Skip to content

Commit 02e634c

Browse files
authored
feat(lb): add match_subdomains & connection_rate_limit (#2986)
* feat(lb): add match_subdomains & connection_rate_limit * add doc
1 parent 15efb77 commit 02e634c

File tree

10 files changed

+2039
-944
lines changed

10 files changed

+2039
-944
lines changed

docs/data-sources/lb_routes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ In addition to all arguments above, the following attributes are exported:
3838
- `backend_id` - The backend ID to redirect to
3939
- `created_at` - The date on which the route was created (RFC 3339 format).
4040
- `update_at` - The date on which the route was last updated (RFC 3339 format).
41+
- `match_subdomains` - If true, all subdomains will match.
4142
- `match_sni` - Server Name Indication TLS extension field from an incoming connection made via an SSL/TLS transport layer.
4243
- `match_host_header` - Specifies the host of the server to which the request is being sent.

docs/resources/lb_frontend.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ The following arguments are supported:
171171

172172
- `enable_http3` - (Default: `false`) Activates HTTP/3 protocol.
173173

174+
- `connection_rate_limit` - (Optional) The rate limit for new connections established on this frontend. Use 0 value to disable, else value is connections per second.
175+
174176
- `acl` - (Optional) A list of ACL rules to apply to the Load Balancer frontend. Defined below.
175177

176178
## acl

docs/resources/lb_route.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ The following arguments are supported:
7979

8080
- `backend_id` - (Required) The ID of the backend the route is associated with.
8181
- `frontend_id` - (Required) The ID of the frontend the route is associated with.
82+
- `match_subdomains` - (Default: `false`) If true, all subdomains will match.
8283
- `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.
8384
Only one of `match_sni` and `match_host_header` should be specified.
8485

internal/services/lb/frontend.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ func ResourceFrontend() *schema.Resource {
218218
Optional: true,
219219
Default: false,
220220
},
221+
"connection_rate_limit": {
222+
Type: schema.TypeInt,
223+
Optional: true,
224+
Description: "Rate limit for new connections established on this frontend. Use 0 value to disable, else value is connections per second",
225+
},
221226
},
222227
}
223228
}
@@ -265,13 +270,14 @@ func resourceLbFrontendCreate(ctx context.Context, d *schema.ResourceData, m int
265270
}
266271

267272
createFrontendRequest := &lbSDK.ZonedAPICreateFrontendRequest{
268-
Zone: zone,
269-
LBID: lbID,
270-
Name: types.ExpandOrGenerateString(d.Get("name"), "lb-frt"),
271-
InboundPort: int32(d.Get("inbound_port").(int)),
272-
BackendID: locality.ExpandID(d.Get("backend_id")),
273-
TimeoutClient: timeoutClient,
274-
EnableHTTP3: d.Get("enable_http3").(bool),
273+
Zone: zone,
274+
LBID: lbID,
275+
Name: types.ExpandOrGenerateString(d.Get("name"), "lb-frt"),
276+
InboundPort: int32(d.Get("inbound_port").(int)),
277+
BackendID: locality.ExpandID(d.Get("backend_id")),
278+
TimeoutClient: timeoutClient,
279+
EnableHTTP3: d.Get("enable_http3").(bool),
280+
ConnectionRateLimit: types.ExpandUint32Ptr(d.Get("connection_rate_limit")),
275281
}
276282

277283
certificatesRaw, certificatesExist := d.GetOk("certificate_ids")
@@ -319,6 +325,7 @@ func resourceLbFrontendRead(ctx context.Context, d *schema.ResourceData, m inter
319325
_ = d.Set("inbound_port", int(frontend.InboundPort))
320326
_ = d.Set("timeout_client", types.FlattenDuration(frontend.TimeoutClient))
321327
_ = d.Set("enable_http3", frontend.EnableHTTP3)
328+
_ = d.Set("connection_rate_limit", types.FlattenUint32Ptr(frontend.ConnectionRateLimit))
322329

323330
if frontend.Certificate != nil { //nolint:staticcheck
324331
_ = d.Set("certificate_id", zonal.NewIDString(zone, frontend.Certificate.ID)) //nolint:staticcheck
@@ -474,14 +481,15 @@ func resourceLbFrontendUpdate(ctx context.Context, d *schema.ResourceData, m int
474481
}
475482

476483
req := &lbSDK.ZonedAPIUpdateFrontendRequest{
477-
Zone: zone,
478-
FrontendID: ID,
479-
Name: types.ExpandOrGenerateString(d.Get("name"), "lb-frt"),
480-
InboundPort: int32(d.Get("inbound_port").(int)),
481-
BackendID: locality.ExpandID(d.Get("backend_id")),
482-
TimeoutClient: timeoutClient,
483-
CertificateIDs: types.ExpandSliceIDsPtr(d.Get("certificate_ids")),
484-
EnableHTTP3: d.Get("enable_http3").(bool),
484+
Zone: zone,
485+
FrontendID: ID,
486+
Name: types.ExpandOrGenerateString(d.Get("name"), "lb-frt"),
487+
InboundPort: int32(d.Get("inbound_port").(int)),
488+
BackendID: locality.ExpandID(d.Get("backend_id")),
489+
TimeoutClient: timeoutClient,
490+
CertificateIDs: types.ExpandSliceIDsPtr(d.Get("certificate_ids")),
491+
EnableHTTP3: d.Get("enable_http3").(bool),
492+
ConnectionRateLimit: types.ExpandUint32Ptr(d.Get("connection_rate_limit")),
485493
}
486494

487495
_, err = lbAPI.UpdateFrontend(req, scw.WithContext(ctx))

internal/services/lb/frontend_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestAccFrontend_Basic(t *testing.T) {
5050
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "inbound_port", "80"),
5151
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "timeout_client", ""),
5252
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "enable_http3", "false"),
53+
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "connection_rate_limit", "0"),
5354
),
5455
},
5556
{
@@ -73,6 +74,7 @@ func TestAccFrontend_Basic(t *testing.T) {
7374
inbound_port = 443
7475
timeout_client = "30s"
7576
enable_http3 = true
77+
connection_rate_limit = 100
7678
}
7779
`,
7880
Check: resource.ComposeTestCheckFunc(
@@ -81,6 +83,7 @@ func TestAccFrontend_Basic(t *testing.T) {
8183
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "inbound_port", "443"),
8284
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "timeout_client", "30s"),
8385
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "enable_http3", "true"),
86+
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "connection_rate_limit", "100"),
8487
),
8588
},
8689
},

internal/services/lb/route.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func ResourceRoute() *schema.Resource {
5555
Description: "Specifies the host of the server to which the request is being sent",
5656
ConflictsWith: []string{"match_sni"},
5757
},
58+
"match_subdomains": {
59+
Type: schema.TypeBool,
60+
Description: "If true, all subdomains will match",
61+
Optional: true,
62+
Default: false,
63+
},
5864
"created_at": {
5965
Type: schema.TypeString,
6066
Computed: true,
@@ -94,8 +100,9 @@ func resourceLbRouteCreate(ctx context.Context, d *schema.ResourceData, m interf
94100
FrontendID: frontID,
95101
BackendID: backID,
96102
Match: &lbSDK.RouteMatch{
97-
Sni: types.ExpandStringPtr(d.Get("match_sni")),
98-
HostHeader: types.ExpandStringPtr(d.Get("match_host_header")),
103+
Sni: types.ExpandStringPtr(d.Get("match_sni")),
104+
HostHeader: types.ExpandStringPtr(d.Get("match_host_header")),
105+
MatchSubdomains: d.Get("match_subdomains").(bool),
99106
},
100107
}
101108

@@ -133,6 +140,7 @@ func resourceLbRouteRead(ctx context.Context, d *schema.ResourceData, m interfac
133140
_ = d.Set("backend_id", zonal.NewIDString(zone, route.BackendID))
134141
_ = d.Set("match_sni", types.FlattenStringPtr(route.Match.Sni))
135142
_ = d.Set("match_host_header", types.FlattenStringPtr(route.Match.HostHeader))
143+
_ = d.Set("match_subdomains", route.Match.MatchSubdomains)
136144
_ = d.Set("created_at", types.FlattenTime(route.CreatedAt))
137145
_ = d.Set("updated_at", types.FlattenTime(route.UpdatedAt))
138146

@@ -159,8 +167,9 @@ func resourceLbRouteUpdate(ctx context.Context, d *schema.ResourceData, m interf
159167
RouteID: ID,
160168
BackendID: backID,
161169
Match: &lbSDK.RouteMatch{
162-
Sni: types.ExpandStringPtr(d.Get("match_sni")),
163-
HostHeader: types.ExpandStringPtr(d.Get("match_host_header")),
170+
Sni: types.ExpandStringPtr(d.Get("match_sni")),
171+
HostHeader: types.ExpandStringPtr(d.Get("match_host_header")),
172+
MatchSubdomains: d.Get("match_subdomains").(bool),
164173
},
165174
}
166175

internal/services/lb/route_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,41 @@ func TestAccRoute_WithSNI(t *testing.T) {
4848
Check: resource.ComposeTestCheckFunc(
4949
isRoutePresent(tt, "scaleway_lb_route.rt01"),
5050
resource.TestCheckResourceAttr("scaleway_lb_route.rt01", "match_sni", "sni.scaleway.com"),
51+
resource.TestCheckResourceAttr("scaleway_lb_route.rt01", "match_subdomains", "false"),
52+
resource.TestCheckResourceAttrSet("scaleway_lb_route.rt01", "created_at"),
53+
resource.TestCheckResourceAttrSet("scaleway_lb_route.rt01", "updated_at"),
54+
),
55+
},
56+
{
57+
Config: `
58+
resource scaleway_lb_ip ip01 {}
59+
resource scaleway_lb lb01 {
60+
ip_id = scaleway_lb_ip.ip01.id
61+
name = "test-lb"
62+
type = "lb-s"
63+
}
64+
resource scaleway_lb_backend bkd01 {
65+
lb_id = scaleway_lb.lb01.id
66+
forward_protocol = "tcp"
67+
forward_port = 80
68+
proxy_protocol = "none"
69+
}
70+
resource scaleway_lb_frontend frt01 {
71+
lb_id = scaleway_lb.lb01.id
72+
backend_id = scaleway_lb_backend.bkd01.id
73+
inbound_port = 80
74+
}
75+
resource scaleway_lb_route rt01 {
76+
frontend_id = scaleway_lb_frontend.frt01.id
77+
backend_id = scaleway_lb_backend.bkd01.id
78+
match_sni = "sni.scaleway.com"
79+
match_subdomains = true
80+
}
81+
`,
82+
Check: resource.ComposeTestCheckFunc(
83+
isRoutePresent(tt, "scaleway_lb_route.rt01"),
84+
resource.TestCheckResourceAttr("scaleway_lb_route.rt01", "match_sni", "sni.scaleway.com"),
85+
resource.TestCheckResourceAttr("scaleway_lb_route.rt01", "match_subdomains", "true"),
5186
resource.TestCheckResourceAttrSet("scaleway_lb_route.rt01", "created_at"),
5287
resource.TestCheckResourceAttrSet("scaleway_lb_route.rt01", "updated_at"),
5388
),

internal/services/lb/routes_data_source.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ func DataSourceRoutes() *schema.Resource {
4646
Computed: true,
4747
Type: schema.TypeString,
4848
},
49+
"match_subdomains": {
50+
Computed: true,
51+
Type: schema.TypeBool,
52+
},
4953
"created_at": {
5054
Computed: true,
5155
Type: schema.TypeString,
@@ -94,6 +98,7 @@ func DataSourceLbRoutesRead(ctx context.Context, d *schema.ResourceData, m inter
9498
rawRoute["update_at"] = types.FlattenTime(route.UpdatedAt)
9599
rawRoute["match_sni"] = types.FlattenStringPtr(route.Match.Sni)
96100
rawRoute["match_host_header"] = types.FlattenStringPtr(route.Match.HostHeader)
101+
rawRoute["match_subdomains"] = route.Match.MatchSubdomains
97102

98103
routes = append(routes, rawRoute)
99104
}

0 commit comments

Comments
 (0)