cloudflare-go icon indicating copy to clipboard operation
cloudflare-go copied to clipboard

UpdateLogpushJobParams: Make it possible to remove logpull_options on update

Open dloebl opened this issue 1 year ago • 7 comments

Description

For reference: #1709 Make it possible to remove the logpull_options on update. I think this is still an issue with the Cloudflare API: I would expect a PUT to overwrite the existing resource, not only change the specified values.

Before: PUT request (TF_LOG=trace output):

PUT /client/v4/zones/[redacted]/logpush/jobs/[redacted] HTTP/1.1
Host: api.cloudflare.com
User-Agent: terraform-provider-cloudflare/dev terraform-plugin-sdk/2.32.0 terraform/1.7.5
Content-Type: application/json
Body: {"dataset":"http_requests","enabled":false,"name":"example","output_options":{"field_names":[],"output_type":"ndjson","record_prefix":"{","record_suffix":"}","field_delimiter":",","timestamp_format":"unixnano","sample_rate":1,"CVE-2021-44228":false},"destination_conf":"[redacted]","frequency":"high"}

With this change: PUT request (TF_LOG=trace output):

PUT /client/v4/zones/[redacted]/logpush/jobs/[redacted] HTTP/1.1
Host: api.cloudflare.com
User-Agent: terraform-provider-cloudflare/dev terraform-plugin-sdk/2.32.0 terraform/1.7.5
Body: {"dataset":"http_requests","enabled":false,"name":"example","logpull_options":"","output_options":{"field_names":[],"output_type":"ndjson","record_prefix":"{","record_suffix":"}","field_delimiter":",","timestamp_format":"unixnano","sample_rate":1,"CVE-2021-44228":false},"destination_conf":"[redacted]","frequency":"high"}

Output of the second terraform plan

No changes. Your infrastructure matches the configuration.

Types of changes

What sort of change does your code introduce/modify?

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.
  • [ ] This change is using publicly documented in cloudflare/api-schemas and relies on stable APIs.

dloebl avatar Apr 09 '24 15:04 dloebl

changelog detected :white_check_mark:

github-actions[bot] avatar Apr 09 '24 15:04 github-actions[bot]

we shouldn't be sending empty strings to the API in order to remove values when using PUT given it should represent the final state of the resource. the omitempty here is the correct way of handling it so we i can't accept the PR as is.

let me check with the internal team as to which behaviour we are expecting here.

jacobbednarz avatar Apr 10 '24 04:04 jacobbednarz

Thanks Jacob! Yeah, I think it would be better to solve this right at the API level. Just let me know in case further details are needed.

dloebl avatar Apr 10 '24 05:04 dloebl

@jacobbednarz any update on this getting resolved upstream in the API ?

sbfaulkner avatar Apr 16 '24 14:04 sbfaulkner

no further updates at this point. the team have it in their backlog to investigate and look at a fix to maintain compatibility.

the output_options takes precedence over logput_options though so you should be fine defining the newer version and it taking effect.

jacobbednarz avatar Apr 18 '24 03:04 jacobbednarz

We've recently opened a support ticket regarding this, as a workaround we keep logpull_options = "" after migrating to output_options in our TF definitions until the API gets fixed.

josip-stanic avatar May 22 '24 16:05 josip-stanic

We've recently opened a support ticket regarding this, as a workaround we keep logpull_options = "" after migrating to output_options in our TF definitions until the API gets fixed.

You can also ignore that field, after setting it to "", so that it doesn't show up in plan and apply output, using the lifecycle field:

  lifecycle {
    ignore_changes = [
      logpull_options,
    ]
  }

diarmuidie avatar May 27 '24 09:05 diarmuidie