fix: send null for removed metadata keys on updates#19
Merged
Conversation
…ates WorkOS merges metadata on PUT updates rather than replacing it. To delete a key, the API requires sending null for that key's value. The provider was using map[string]string which cannot represent null, so removed keys persisted silently on the API side causing Terraform "inconsistent result after apply" errors. Changes update request structs to map[string]*string and computes key deletions by comparing old vs new metadata, sending nil (JSON null) for any keys present in state but absent from the plan. Also handles the edge case where metadata is fully removed from config. Fixes #18 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
Contributor
Author
|
This fix landed in v2.2.1. All acceptance tests now pass — including Follow-up to the great work by @danielloader in #16 which surfaced this underlying metadata merge behaviour in the WorkOS API. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
nullmap[string]stringwhich can't representnull, so removed metadata keys silently persisted on the API sideTestAccUserResource_withExternalIDAndMetadatato fail with "Provider produced inconsistent result after apply"UserUpdateRequest.MetadataandOrganizationUpdateRequest.Metadatatomap[string]*stringnil(JSONnull) for removed keysFixes #18
Test plan
go build ./...passesTestAccUserResource_withExternalIDAndMetadatapasses (step 3 — metadata key removal)TestAccOrganizationResource_WithMetadataAndExternalIDpasses🤖 Generated with Claude Code