Skip to content

fix: send null for removed metadata keys on updates#19

Merged
sionsmith merged 1 commit into
mainfrom
fix/metadata-key-deletion
Apr 9, 2026
Merged

fix: send null for removed metadata keys on updates#19
sionsmith merged 1 commit into
mainfrom
fix/metadata-key-deletion

Conversation

@sionsmith

Copy link
Copy Markdown
Contributor

Summary

  • WorkOS API merges metadata on PUT updates instead of replacing it — to delete a key you must send null
  • The provider used map[string]string which can't represent null, so removed metadata keys silently persisted on the API side
  • This caused TestAccUserResource_withExternalIDAndMetadata to fail with "Provider produced inconsistent result after apply"
  • Changes UserUpdateRequest.Metadata and OrganizationUpdateRequest.Metadata to map[string]*string
  • Update methods now compare old vs new metadata and send nil (JSON null) for removed keys
  • Also handles the edge case where metadata is entirely removed from config (set → null)

Fixes #18

Test plan

  • go build ./... passes
  • TestAccUserResource_withExternalIDAndMetadata passes (step 3 — metadata key removal)
  • TestAccOrganizationResource_WithMetadataAndExternalID passes
  • All other existing acceptance tests continue to pass

🤖 Generated with Claude Code

…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>
@sionsmith sionsmith merged commit 988a8ac into main Apr 9, 2026
6 checks passed
@sionsmith

Copy link
Copy Markdown
Contributor Author

This fix landed in v2.2.1. All acceptance tests now pass — including TestAccUserResource_withExternalIDAndMetadata which was previously failing.

Follow-up to the great work by @danielloader in #16 which surfaced this underlying metadata merge behaviour in the WorkOS API.

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.

fix: metadata key deletion broken on user and organization updates

1 participant