Skip to content

fix: handle boolean strings from Splunk Cloud API for HEC useACK field#232

Open
pgiraultmatz wants to merge 1 commit into
splunk:masterfrom
pgiraultmatz:fix/hec-useack-splunk-cloud-boolean-unmarshal
Open

fix: handle boolean strings from Splunk Cloud API for HEC useACK field#232
pgiraultmatz wants to merge 1 commit into
splunk:masterfrom
pgiraultmatz:fix/hec-useack-splunk-cloud-boolean-unmarshal

Conversation

@pgiraultmatz

Copy link
Copy Markdown

Problem

On Splunk Cloud deployments, terraform apply fails with:

json: invalid use of ,string struct tag, trying to unmarshal "false" into int

This happens because Splunk Cloud returns "useACK": "false" in HEC token API responses, while the HttpEventCollectorObject struct declares UseACK as int with a json:",string" tag — which only handles integer strings like "0" or "1".

Splunk Enterprise returns "0"/"1", Splunk Cloud returns "false"/"true". The existing struct tag cannot handle both.

Fix

Introduce SplunkBoolInt, a custom int type with a UnmarshalJSON that accepts:

  • Boolean strings: "true" → 1, "false" → 0 (Splunk Cloud)
  • Integer strings: "1" → 1, "0" → 0 (Splunk Enterprise)
  • Raw integers: 1 → 1, 0 → 0

MarshalJSON serializes back as an integer string ("0"/"1") to preserve compatibility with the Splunk API write path.

Files changed

  • client/models/splunk_bool_int.go — new SplunkBoolInt type
  • client/models/splunk_bool_int_test.go — unit tests covering all cases including the Splunk Cloud regression
  • client/models/http_event_collector.goUseACK field changed from int to SplunkBoolInt
  • splunk/resource_splunk_inputs_http_event_collector.go — cast updated accordingly

Testing

go test ./client/models/... -v

All tests pass. The TestHttpEventCollectorObject_UnmarshalUseACK test directly reproduces the Splunk Cloud API response that triggered the bug.

Notes

The same int json:",string" pattern exists in global_http_event_collector.go and saved_searches.go. Those fields may be affected by the same issue on Splunk Cloud — SplunkBoolInt can be reused to fix them incrementally.

Splunk Cloud returns "true"/"false" strings for the useACK field in HEC
token responses, while Splunk Enterprise returns "0"/"1". The existing
json:",string" struct tag only handles integer strings, causing an unmarshal
error on Splunk Cloud deployments.

Introduce SplunkBoolInt, a custom int type with a JSON unmarshaler that
accepts both boolean strings ("true"/"false") and integer strings ("0"/"1"),
fixing the panic:
  json: invalid use of ,string struct tag, trying to unmarshal "false" into int
@pgiraultmatz

Copy link
Copy Markdown
Author

cc @rrossetti-splunk @micahkemp-splunk — would appreciate a review when you get a chance. This fixes a crash on Splunk Cloud deployments where the API returns boolean strings for useACK instead of integer strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant