fix: add IsUnknown() checks for Optional+Computed fields#16
Conversation
When Optional+Computed attributes are not set by the user, Terraform marks them as unknown (not null) during planning. Missing IsUnknown() guards caused "Value Conversion Error" crashes when native Go types like map[string]string received unknown values they cannot represent. Fixes user resource (metadata, external_id) and organization membership resource (role_slug) to match the pattern already used in the organization resource. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The WorkOS API returns role as a nested object `{"role": {"slug": "admin"}}`
but the OrganizationMembership struct mapped it as a flat `role_slug` field,
causing the role to be silently dropped during JSON deserialization.
This also adds a proper Update function for organization memberships to
support changing role_slug via the API instead of being a no-op read.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Multiple organizations can share the same domains in a WorkOS environment (domains get auto-assigned to all of them), so the provider-side uniqueness validation was incorrectly blocking valid configurations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I've also bolted in a change to undo the unique constant on domains, as with some testing in the Web UI it's possible, and works, to assign domains to multiple organisations and logging into one auto assigns memberships to all of them and that means we shouldn't constrain this in the provider. |
|
Thanks for the contribution @danielloader! 🎉 All three fixes in this PR shipped in v2.2.1. While merging, we noticed one remaining issue: the WorkOS API merges metadata on PUT updates rather than replacing it, so removing metadata keys from a Terraform config didn't actually delete them server-side. This was causing We followed up with #19 to fix that — both |
Summary
IsUnknown()guards onOptional+Computedattributes in the user and organization membership resourcesValue Conversion Errorcrashes because native Go types (map[string]string,string) cannot represent unknown valuesmetadataandexternal_idinresource_user.go, androle_sluginresource_organization_membership.goto match the pattern already used inresource_organization.goTest plan
go build ./...passesworkos_userwithout settingmetadataorexternal_id— should no longer produce "Value Conversion Error"workos_organization_membershipwithrole_slugset — verify it still works as expectedworkos_organization_membershipwithoutrole_slug— should no longer crash🤖 Generated with Claude Code