fix: ensure inventory_mode is properly set when updating hosts #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix
inventory_modeupdate issue by correcting pointer assignment inprepHostsDescription
When updating a host's
inventory_modefrom"manual"to"automatic"using Terraform, the change was not taking effect. Despite a successfulterraform apply, subsequent runs showed the value reverting back to"manual". Additionally, Terraform debug logs revealed that theinventory_modefield was missing from the POST request sent to the Zabbix API. For example, before the fix, the API request looked like this:A warning was also logged:
Root Cause
The root cause was identified in the
prepHostsfunction in host.go. The function is meant to prepare host data before sending it to the API by assigning the pointer forRawInventoryMode. However, the assignment was performed on a temporary variable (h), rather than directly on the slice element, resulting in the change not being reflected in the data sent to the API.Original Code:
Fix
The fix updates the assignment so that it writes directly into the slice element instead of the temporary variable:
Updated Code:
Verification
After applying these changes:
Running
terraform applynow sends a POST request that includes"inventory_mode": "1"(representing"automatic") as expected:The warning about the unexpected new value for
inventory_modeno longer appears.Subsequent
terraform applyruns confirm that the infrastructure state now matches the configuration with no unintended changes.Please review these changes and let me know if you have any questions or need further details.