Skip to content

Commit

Permalink
Merge pull request #1660 from Shopify/jade/support-logpush-filters
Browse files Browse the repository at this point in the history
Add support logpush filters
  • Loading branch information
jacobbednarz committed Jun 8, 2022
2 parents 43b1e60 + 5bd03a6 commit 6809315
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
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/cloudflare_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 @@ -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

0 comments on commit 6809315

Please sign in to comment.