Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Add support logpush filters (cloudflare#1660) (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
yknx4 committed Jun 2, 2022
1 parent f58a5ee commit 5e9224e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
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
```
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 @@ -42,6 +42,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
3 changes: 2 additions & 1 deletion website/docs/r/logpush_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ The following arguments are supported:
* `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.
* `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

0 comments on commit 5e9224e

Please sign in to comment.