Skip to content

Commit 1b08c3e

Browse files
bowrockerrcaril
andauthored
Add Period attribute to logging https endpoint. (#1097)
* Add Period attribute to logging https endpoint. * Change the logging HTTPS endpoint `Period` default to 5. * Changes based on review feedback. * Update tests. * Remove duplicate code. * Adding more variety to Period Values in Tests and Removed state updates --------- Co-authored-by: Richard Carillo <[email protected]> Co-authored-by: Richard Carillo <[email protected]>
1 parent 32ab3b9 commit 1b08c3e

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### BREAKING:
44

55
### ENHANCEMENTS:
6+
- feat(logging/https): add support for Period HTTPS logging endpoint ([#1097](https://github.com/fastly/terraform-provider-fastly/pull/1097))
67

78
- feat(product_enablement): Add enable/disable support for API Discovery ([#1111](https://github.com/fastly/terraform-provider-fastly/pull/1111))
89
- feat(domainsv1/data source): add support for the v1 domains data source ([#1112](https://github.com/fastly/terraform-provider-fastly/pull/1112))

docs/resources/service_compute.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ Optional:
513513
- `json_format` (String) Formats log entries as JSON. Can be either disabled (`0`), array of json (`1`), or newline delimited json (`2`)
514514
- `message_type` (String) How the message should be formatted. Can be either `classic`, `loggly`, `logplex` or `blank`. Default is `classic`
515515
- `method` (String) HTTP method used for request. Can be either `POST` or `PUT`. Default `POST`
516+
- `period` (Number) How frequently, in seconds, batches of log data are sent to the HTTPS endpoint. A value of 0 sends logs at the same interval as the default, which is 5 seconds.
516517
- `processing_region` (String) Region where logs will be processed before streaming to BigQuery. Valid values are 'none', 'us' and 'eu'.
517518
- `request_max_bytes` (Number) The maximum number of bytes sent in one request
518519
- `request_max_entries` (Number) The maximum number of logs sent in one request

docs/resources/service_vcl.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ Optional:
814814
- `json_format` (String) Formats log entries as JSON. Can be either disabled (`0`), array of json (`1`), or newline delimited json (`2`)
815815
- `message_type` (String) How the message should be formatted. Can be either `classic`, `loggly`, `logplex` or `blank`. Default is `classic`
816816
- `method` (String) HTTP method used for request. Can be either `POST` or `PUT`. Default `POST`
817+
- `period` (Number) How frequently, in seconds, batches of log data are sent to the HTTPS endpoint. A value of 0 sends logs at the same interval as the default, which is 5 seconds.
817818
- `placement` (String) Where in the generated VCL the logging call should be placed
818819
- `processing_region` (String) Region where logs will be processed before streaming to BigQuery. Valid values are 'none', 'us' and 'eu'.
819820
- `request_max_bytes` (Number) The maximum number of bytes sent in one request

fastly/block_fastly_service_logging_https.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ func (h *HTTPSLoggingServiceAttributeHandler) GetSchema() *schema.Schema {
9292
Required: true,
9393
Description: "The unique name of the HTTPS logging endpoint. It is important to note that changing this attribute will delete and recreate the resource",
9494
},
95+
"period": {
96+
Type: schema.TypeInt,
97+
Optional: true,
98+
Default: 5,
99+
Description: "How frequently, in seconds, batches of log data are sent to the HTTPS endpoint. A value of 0 sends logs at the same interval as the default, which is 5 seconds.",
100+
ValidateFunc: validation.IntAtLeast(1),
101+
},
95102
"processing_region": {
96103
Type: schema.TypeString,
97104
Optional: true,
@@ -261,6 +268,9 @@ func (h *HTTPSLoggingServiceAttributeHandler) Update(ctx context.Context, d *sch
261268
if v, ok := modified["json_format"]; ok {
262269
opts.JSONFormat = gofastly.ToPointer(v.(string))
263270
}
271+
if v, ok := modified["period"]; ok {
272+
opts.Period = gofastly.ToPointer(v.(int))
273+
}
264274
if v, ok := modified["placement"]; ok {
265275
opts.Placement = gofastly.ToPointer(v.(string))
266276
}
@@ -294,6 +304,18 @@ func (h *HTTPSLoggingServiceAttributeHandler) Update(ctx context.Context, d *sch
294304
return nil
295305
}
296306

307+
// pruneVCLLoggingAttributes removes VCL-only attributes from Compute service data.
308+
// For HTTPS logging, period is not VCL-only, so we preserve it.
309+
func (h *HTTPSLoggingServiceAttributeHandler) pruneVCLLoggingAttributes(data map[string]any) {
310+
if h.GetServiceMetadata().serviceType == ServiceTypeCompute {
311+
delete(data, "format")
312+
delete(data, "format_version")
313+
delete(data, "placement")
314+
delete(data, "response_condition")
315+
// Note: period is NOT deleted for HTTPS logging as it's available for both VCL and Compute
316+
}
317+
}
318+
297319
// Delete deletes the resource.
298320
func (h *HTTPSLoggingServiceAttributeHandler) Delete(ctx context.Context, d *schema.ResourceData, resource map[string]any, serviceVersion int, conn *gofastly.Client) error {
299321
opts := h.buildDelete(resource, d.Id(), serviceVersion)
@@ -357,6 +379,9 @@ func flattenHTTPS(remoteState []*gofastly.HTTPS, localState []any) []map[string]
357379
if resource.RequestMaxEntries != nil {
358380
data["request_max_entries"] = *resource.RequestMaxEntries
359381
}
382+
if resource.Period != nil {
383+
data["period"] = *resource.Period
384+
}
360385
if resource.RequestMaxBytes != nil {
361386
data["request_max_bytes"] = *resource.RequestMaxBytes
362387
}
@@ -434,6 +459,7 @@ func (h *HTTPSLoggingServiceAttributeHandler) buildCreate(httpsMap any, serviceI
434459
MessageType: gofastly.ToPointer(resource["message_type"].(string)),
435460
Method: gofastly.ToPointer(resource["method"].(string)),
436461
Name: gofastly.ToPointer(resource["name"].(string)),
462+
Period: gofastly.ToPointer(resource["period"].(int)),
437463
RequestMaxBytes: gofastly.ToPointer(resource["request_max_bytes"].(int)),
438464
RequestMaxEntries: gofastly.ToPointer(resource["request_max_entries"].(int)),
439465
ServiceID: serviceID,

fastly/block_fastly_service_logging_https_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestAccFastlyServiceVCL_httpslogging_basic(t *testing.T) {
3131
MessageType: gofastly.ToPointer("blank"),
3232
Method: gofastly.ToPointer("PUT"),
3333
Name: gofastly.ToPointer("httpslogger"),
34+
Period: gofastly.ToPointer(10),
3435
RequestMaxBytes: gofastly.ToPointer(0),
3536
RequestMaxEntries: gofastly.ToPointer(0),
3637
ResponseCondition: gofastly.ToPointer(""),
@@ -52,6 +53,7 @@ func TestAccFastlyServiceVCL_httpslogging_basic(t *testing.T) {
5253
MessageType: gofastly.ToPointer("blank"),
5354
Method: gofastly.ToPointer("POST"),
5455
Name: gofastly.ToPointer("httpslogger"),
56+
Period: gofastly.ToPointer(30),
5557
RequestMaxBytes: gofastly.ToPointer(0),
5658
RequestMaxEntries: gofastly.ToPointer(0),
5759
ResponseCondition: gofastly.ToPointer(""),
@@ -72,6 +74,7 @@ func TestAccFastlyServiceVCL_httpslogging_basic(t *testing.T) {
7274
MessageType: gofastly.ToPointer("blank"),
7375
Method: gofastly.ToPointer("POST"),
7476
Name: gofastly.ToPointer("httpslogger2"),
77+
Period: gofastly.ToPointer(60),
7578
RequestMaxBytes: gofastly.ToPointer(1000),
7679
RequestMaxEntries: gofastly.ToPointer(0),
7780
ResponseCondition: gofastly.ToPointer(""),
@@ -92,6 +95,7 @@ func TestAccFastlyServiceVCL_httpslogging_basic(t *testing.T) {
9295
MessageType: gofastly.ToPointer("blank"),
9396
Method: gofastly.ToPointer("PUT"),
9497
Name: gofastly.ToPointer("httpslogger3"),
98+
Period: gofastly.ToPointer(120),
9599
RequestMaxBytes: gofastly.ToPointer(0),
96100
RequestMaxEntries: gofastly.ToPointer(0),
97101
ResponseCondition: gofastly.ToPointer(""),
@@ -156,6 +160,7 @@ func TestAccFastlyServiceVCL_httpslogging_basic_compute(t *testing.T) {
156160
MessageType: gofastly.ToPointer("blank"),
157161
Method: gofastly.ToPointer("PUT"),
158162
Name: gofastly.ToPointer("httpslogger"),
163+
Period: gofastly.ToPointer(300),
159164
RequestMaxBytes: gofastly.ToPointer(0),
160165
RequestMaxEntries: gofastly.ToPointer(0),
161166
ServiceVersion: gofastly.ToPointer(1),
@@ -281,6 +286,7 @@ resource "fastly_service_vcl" "foo" {
281286
name = "httpslogger3"
282287
method = "PUT"
283288
format = %q
289+
period = 120
284290
url = "https://example.com/logs/3"
285291
}
286292
@@ -306,6 +312,7 @@ resource "fastly_service_vcl" "foo" {
306312
logging_https {
307313
name = "httpslogger"
308314
method = "PUT"
315+
period = 10
309316
url = "https://example.com/logs/1"
310317
compression_codec = "zstd"
311318
processing_region = "us"
@@ -339,7 +346,8 @@ resource "fastly_service_compute" "foo" {
339346
method = "PUT"
340347
url = "https://example.com/logs/1"
341348
compression_codec = "zstd"
342-
processing_region = "us"
349+
period = 300
350+
processing_region = "us"
343351
}
344352
345353
package {
@@ -370,6 +378,7 @@ resource "fastly_service_vcl" "foo" {
370378
name = "httpslogger"
371379
format = %q
372380
method = "POST"
381+
period = 30
373382
url = "https://example.com/logs/1"
374383
compression_codec = "snappy"
375384
}
@@ -379,6 +388,7 @@ resource "fastly_service_vcl" "foo" {
379388
format = %q
380389
method = "POST"
381390
url = "https://example.com/logs/2"
391+
period = 60
382392
request_max_bytes = 1000
383393
gzip_level = 5
384394
}
@@ -405,6 +415,7 @@ func TestResourceFastlyFlattenHTTPS(t *testing.T) {
405415
GzipLevel: gofastly.ToPointer(0),
406416
Format: gofastly.ToPointer(LoggingHTTPSDefaultFormat),
407417
FormatVersion: gofastly.ToPointer(2),
418+
Period: gofastly.ToPointer(5),
408419
ProcessingRegion: gofastly.ToPointer("eu"),
409420
},
410421
},
@@ -420,6 +431,7 @@ func TestResourceFastlyFlattenHTTPS(t *testing.T) {
420431
"format": LoggingHTTPSDefaultFormat,
421432
"format_version": 2,
422433
"gzip_level": 0,
434+
"period": 5,
423435
"processing_region": "eu",
424436
},
425437
},

fastly/service_attribute_definition.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ func (h *DefaultServiceAttributeHandler) MustProcess(d *schema.ResourceData, _ b
6565
type VCLLoggingAttributes struct {
6666
format string
6767
formatVersion *int
68+
period *int
6869
placement string
6970
responseCondition string
7071
}
7172

7273
// getVCLLoggingAttributes provides default values to Compute services for VCL only logging attributes.
7374
func (h *DefaultServiceAttributeHandler) getVCLLoggingAttributes(data map[string]any) VCLLoggingAttributes {
7475
vla := VCLLoggingAttributes{
76+
period: gofastly.ToPointer(3600),
7577
placement: "none",
7678
}
7779
if h.GetServiceMetadata().serviceType == ServiceTypeVCL {
@@ -81,6 +83,9 @@ func (h *DefaultServiceAttributeHandler) getVCLLoggingAttributes(data map[string
8183
if val, ok := data["format_version"]; ok {
8284
vla.formatVersion = gofastly.ToPointer(val.(int))
8385
}
86+
if val, ok := data["period"]; ok {
87+
vla.period = gofastly.ToPointer(val.(int))
88+
}
8489
if val, ok := data["placement"]; ok {
8590
vla.placement = val.(string)
8691
}
@@ -97,6 +102,7 @@ func (h *DefaultServiceAttributeHandler) pruneVCLLoggingAttributes(data map[stri
97102
if h.GetServiceMetadata().serviceType == ServiceTypeCompute {
98103
delete(data, "format")
99104
delete(data, "format_version")
105+
delete(data, "period")
100106
delete(data, "placement")
101107
delete(data, "response_condition")
102108
}

0 commit comments

Comments
 (0)