Skip to content

Commit

Permalink
LogpushJob.Filter is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfaulkner committed Jun 20, 2022
1 parent 9ed7f06 commit 69d8afa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/1712.txt
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_logpush_job: Fix for optional `filter` attribute
```
11 changes: 7 additions & 4 deletions internal/provider/resource_cloudflare_logpush_job.go
Expand Up @@ -81,7 +81,7 @@ func getJobFromResource(d *schema.ResourceData) (cloudflare.LogpushJob, *AccessI
if err != nil {
return job, identifier, err
}
job.Filter = jobFilter
job.Filter = &jobFilter
}

return job, identifier, nil
Expand Down Expand Up @@ -118,13 +118,15 @@ func resourceCloudflareLogpushJobRead(ctx context.Context, d *schema.ResourceDat
return nil
}

if job.Filter.Where.Validate() == nil {
filterstr, err := json.Marshal(job.Filter)
var filter string

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

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

d.Set("name", job.Name)
Expand All @@ -133,6 +135,7 @@ func resourceCloudflareLogpushJobRead(ctx context.Context, d *schema.ResourceDat
d.Set("destination_conf", job.DestinationConf)
d.Set("ownership_challenge", d.Get("ownership_challenge"))
d.Set("frequency", job.Frequency)
d.Set("filter", filter)

return nil
}
Expand Down

0 comments on commit 69d8afa

Please sign in to comment.