Skip to content

Commit 8ab640f

Browse files
authored
feat(lb): add support for enable_access_logs (#3216)
* feat(lb): add support for enable_access_logs * add test * update descriptions
1 parent 4ae66ec commit 8ab640f

File tree

6 files changed

+614
-561
lines changed

6 files changed

+614
-561
lines changed

docs/data-sources/lb_frontends.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ In addition to all arguments above, the following attributes are exported:
4040
~> **Important:** LB frontend IDs are [zoned](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111`
4141
- `inbound_port` - TCP port the frontend listens to.
4242
- `created_at` - The date on which the frontend was created (RFC 3339 format).
43-
- `update_at` - The date aont which the frontend was last updated (RFC 3339 format).
43+
- `update_at` - The date on which the frontend was last updated (RFC 3339 format).
4444
- `backend_id` - The Load Balancer backend ID this frontend is attached to.
4545
~> **Important:** Load Balancer backend IDs are [zoned](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111`
4646
- `timeout_client` - Maximum inactivity time on the client side.
4747
- `certificate_ids` - List of certificate IDs that are used by the frontend.
4848
- `enable_http3` - Whether HTTP/3 protocol is activated.
49+
- `connection_rate_limit` - The rate limit for new connections established on this frontend. Use 0 value to disable, else value is connections per second.
50+
- `enable_access_logs` - Defines whether to enable access logs on the frontend.

docs/resources/lb_frontend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ The following arguments are supported:
173173

174174
- `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.
175175

176+
- `enable_access_logs` - (Default: `false`) Defines whether to enable access logs on the frontend.
177+
176178
- `acl` - (Optional) A list of ACL rules to apply to the Load Balancer frontend. Defined below.
177179

178180
## acl
@@ -221,6 +223,9 @@ In addition to all arguments above, the following attributes are exported:
221223

222224
- `certificate_id` - (Deprecated, use `certificate_ids` instead) First certificate ID used by the frontend.
223225

226+
- `created_at` - The date and time the frontend was created.
227+
228+
- `updated_at` - The date and time the frontend resource was updated.
224229

225230
## Import
226231

internal/services/lb/data_source_lb_frontends.go

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,67 @@ func DataSourceFrontends() *schema.Resource {
3232
Elem: &schema.Resource{
3333
Schema: map[string]*schema.Schema{
3434
"id": {
35-
Computed: true,
36-
Type: schema.TypeString,
35+
Computed: true,
36+
Type: schema.TypeString,
37+
Description: "The load-balancer frontend ID",
3738
},
3839
"name": {
39-
Computed: true,
40-
Type: schema.TypeString,
40+
Computed: true,
41+
Type: schema.TypeString,
42+
Description: "The name of the frontend",
4143
},
4244
"inbound_port": {
43-
Computed: true,
44-
Type: schema.TypeInt,
45+
Computed: true,
46+
Type: schema.TypeInt,
47+
Description: "TCP port to listen on the front side",
4548
},
4649
"backend_id": {
47-
Computed: true,
48-
Type: schema.TypeString,
50+
Computed: true,
51+
Type: schema.TypeString,
52+
Description: "The load-balancer backend ID",
4953
},
5054
"lb_id": {
51-
Computed: true,
52-
Type: schema.TypeString,
55+
Computed: true,
56+
Type: schema.TypeString,
57+
Description: "The load-balancer ID",
5358
},
5459
"timeout_client": {
55-
Computed: true,
56-
Type: schema.TypeString,
60+
Computed: true,
61+
Type: schema.TypeString,
62+
Description: "Set the maximum inactivity time on the client side",
5763
},
5864
"certificate_ids": {
5965
Computed: true,
6066
Type: schema.TypeList,
6167
Elem: &schema.Schema{
6268
Type: schema.TypeString,
6369
},
70+
Description: "Collection of Certificate IDs related to the load balancer and domain",
6471
},
6572
"created_at": {
66-
Computed: true,
67-
Type: schema.TypeString,
73+
Computed: true,
74+
Type: schema.TypeString,
75+
Description: "The date and time of the creation of the frontend",
6876
},
6977
"update_at": {
70-
Computed: true,
71-
Type: schema.TypeString,
78+
Computed: true,
79+
Type: schema.TypeString,
80+
Description: "The date and time of the last update of the frontend",
7281
},
7382
"enable_http3": {
74-
Computed: true,
75-
Type: schema.TypeBool,
83+
Computed: true,
84+
Type: schema.TypeBool,
85+
Description: "Activates HTTP/3 protocol",
86+
},
87+
"connection_rate_limit": {
88+
Computed: true,
89+
Type: schema.TypeInt,
90+
Description: "Rate limit for new connections established on this frontend. Use 0 value to disable, else value is connections per second",
91+
},
92+
"enable_access_logs": {
93+
Computed: true,
94+
Type: schema.TypeBool,
95+
Description: "Defines whether to enable access logs on the frontend",
7696
},
7797
},
7898
},
@@ -117,6 +137,8 @@ func DataSourceLbFrontendsRead(ctx context.Context, d *schema.ResourceData, m an
117137
rawFrontend["backend_id"] = frontend.Backend.ID
118138
rawFrontend["timeout_client"] = types.FlattenDuration(frontend.TimeoutClient)
119139
rawFrontend["enable_http3"] = frontend.EnableHTTP3
140+
rawFrontend["connection_rate_limit"] = types.FlattenUint32Ptr(frontend.ConnectionRateLimit)
141+
rawFrontend["enable_access_logs"] = frontend.EnableAccessLogs
120142

121143
if len(frontend.CertificateIDs) > 0 {
122144
rawFrontend["certificate_ids"] = frontend.CertificateIDs

internal/services/lb/frontend.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ func ResourceFrontend() *schema.Resource {
228228
Optional: true,
229229
Description: "Rate limit for new connections established on this frontend. Use 0 value to disable, else value is connections per second",
230230
},
231+
"enable_access_logs": {
232+
Type: schema.TypeBool,
233+
Description: "Defines whether to enable access logs on the frontend",
234+
Optional: true,
235+
Default: false,
236+
},
237+
"created_at": {
238+
Type: schema.TypeString,
239+
Computed: true,
240+
Description: "The date and time of the creation of the frontend",
241+
},
242+
"updated_at": {
243+
Type: schema.TypeString,
244+
Computed: true,
245+
Description: "The date and time of the last update of the frontend",
246+
},
231247
},
232248
}
233249
}
@@ -283,6 +299,7 @@ func resourceLbFrontendCreate(ctx context.Context, d *schema.ResourceData, m any
283299
TimeoutClient: timeoutClient,
284300
EnableHTTP3: d.Get("enable_http3").(bool),
285301
ConnectionRateLimit: types.ExpandUint32Ptr(d.Get("connection_rate_limit")),
302+
EnableAccessLogs: d.Get("enable_access_logs").(bool),
286303
}
287304

288305
certificatesRaw, certificatesExist := d.GetOk("certificate_ids")
@@ -331,6 +348,9 @@ func resourceLbFrontendRead(ctx context.Context, d *schema.ResourceData, m any)
331348
_ = d.Set("timeout_client", types.FlattenDuration(frontend.TimeoutClient))
332349
_ = d.Set("enable_http3", frontend.EnableHTTP3)
333350
_ = d.Set("connection_rate_limit", types.FlattenUint32Ptr(frontend.ConnectionRateLimit))
351+
_ = d.Set("enable_access_logs", frontend.EnableAccessLogs)
352+
_ = d.Set("created_at", types.FlattenTime(frontend.CreatedAt))
353+
_ = d.Set("updated_at", types.FlattenTime(frontend.UpdatedAt))
334354

335355
if frontend.Certificate != nil { //nolint:staticcheck
336356
_ = d.Set("certificate_id", zonal.NewIDString(zone, frontend.Certificate.ID)) //nolint:staticcheck
@@ -495,6 +515,7 @@ func resourceLbFrontendUpdate(ctx context.Context, d *schema.ResourceData, m any
495515
CertificateIDs: types.ExpandSliceIDsPtr(d.Get("certificate_ids")),
496516
EnableHTTP3: d.Get("enable_http3").(bool),
497517
ConnectionRateLimit: types.ExpandUint32Ptr(d.Get("connection_rate_limit")),
518+
EnableAccessLogs: types.ExpandBoolPtr(d.Get("enable_access_logs")),
498519
}
499520

500521
_, 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
@@ -51,6 +51,7 @@ func TestAccFrontend_Basic(t *testing.T) {
5151
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "timeout_client", ""),
5252
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "enable_http3", "false"),
5353
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "connection_rate_limit", "0"),
54+
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "enable_access_logs", "false"),
5455
),
5556
},
5657
{
@@ -75,6 +76,7 @@ func TestAccFrontend_Basic(t *testing.T) {
7576
timeout_client = "30s"
7677
enable_http3 = true
7778
connection_rate_limit = 100
79+
enable_access_logs = true
7880
}
7981
`,
8082
Check: resource.ComposeTestCheckFunc(
@@ -84,6 +86,7 @@ func TestAccFrontend_Basic(t *testing.T) {
8486
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "timeout_client", "30s"),
8587
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "enable_http3", "true"),
8688
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "connection_rate_limit", "100"),
89+
resource.TestCheckResourceAttr("scaleway_lb_frontend.frt01", "enable_access_logs", "true"),
8790
),
8891
},
8992
},

0 commit comments

Comments
 (0)