Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support logpush filters #1660

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1664.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/logpush_job: Add `filter` field support
yknx4 marked this conversation as resolved.
Show resolved Hide resolved
```
23 changes: 23 additions & 0 deletions internal/provider/resource_cloudflare_logpush_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"encoding/json"
"fmt"
"regexp"
"strconv"
Expand Down Expand Up @@ -60,6 +61,19 @@ func getJobFromResource(d *schema.ResourceData) (cloudflare.LogpushJob, *AccessI
Frequency: d.Get("frequency").(string),
}

filter := d.Get("filter")
if filter != nil {
var jobFilter cloudflare.LogpushJobFilters
if err := json.Unmarshal([]byte(filter.(string)), &jobFilter); err != nil {
return cloudflare.LogpushJob{}, identifier, err
}
err := jobFilter.Where.Validate()
if err != nil {
return job, identifier, err
}
job.Filter = jobFilter
}

return job, identifier, nil
}

Expand Down Expand Up @@ -94,6 +108,15 @@ func resourceCloudflareLogpushJobRead(ctx context.Context, d *schema.ResourceDat
return nil
}

if job.Filter.Where.Validate() == nil {
filterstr, err := json.Marshal(job.Filter)
if err != nil {
return diag.FromErr(err)
}

d.Set("filter", string(filterstr))
}

d.Set("name", job.Name)
d.Set("enabled", job.Enabled)
d.Set("logpull_options", job.LogpullOptions)
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/schema_cloudflare_logpush_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func resourceCloudflareLogpushJobSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Optional: true,
},
"filter": {
Type: schema.TypeString,
Optional: true,
},
"frequency": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 3 additions & 2 deletions templates/resources/cloudflare_logpush_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ The following arguments are supported:
- `logpull_options` - (Optional) Configuration string for the Logshare API. It specifies things like requested fields and timestamp formats. See [Logpull options documentation](https://developers.cloudflare.com/logs/logpush/logpush-configuration-api/understanding-logpush-api/#options).
- `ownership_challenge` - (Optional) Ownership challenge token to prove destination ownership, required when destination is Amazon S3, Google Cloud Storage,
Microsoft Azure or Sumo Logic. See [Developer documentation](https://developers.cloudflare.com/logs/logpush/logpush-configuration-api/understanding-logpush-api/#usage).
- `enabled` - (Optional) Whether to enable the job.
- `frequency` - (Optional) `"high"` or `"low"`. A higher frequency will result in logs being pushed on faster with smaller files. `"low"` frequency will push logs less often with larger files.
* `enabled` - (Optional) Whether to enable the job.
* `frequency` - (Optional) `"high"` or `"low"`. A higher frequency will result in logs being pushed on faster with smaller files. `"low"` frequency will push logs less often with larger files.
* `filter` - (Optional) Use filters to select the events to include and/or remove from your logs. For more information, refer to [Filters](https://developers.cloudflare.com/logs/reference/logpush-api-configuration/filters/).

## Import

Expand Down