Skip to content

fix: add IsUnknown() checks for Optional+Computed fields#16

Merged
sionsmith merged 3 commits into
osodevops:mainfrom
danielloader:fix/unknown-value-handling
Apr 9, 2026
Merged

fix: add IsUnknown() checks for Optional+Computed fields#16
sionsmith merged 3 commits into
osodevops:mainfrom
danielloader:fix/unknown-value-handling

Conversation

@danielloader

Copy link
Copy Markdown
Contributor

Summary

  • Adds missing IsUnknown() guards on Optional+Computed attributes in the user and organization membership resources
  • When these attributes are not set by the user, Terraform marks them as unknown (not null) during planning — the missing check caused Value Conversion Error crashes because native Go types (map[string]string, string) cannot represent unknown values
  • Fixes metadata and external_id in resource_user.go, and role_slug in resource_organization_membership.go to match the pattern already used in resource_organization.go

Test plan

  • go build ./... passes
  • Apply a config that creates a workos_user without setting metadata or external_id — should no longer produce "Value Conversion Error"
  • Apply a config that creates a workos_organization_membership with role_slug set — verify it still works as expected
  • Apply a config that creates a workos_organization_membership without role_slug — should no longer crash

🤖 Generated with Claude Code

danielloader and others added 3 commits March 31, 2026 12:39
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>
@danielloader

Copy link
Copy Markdown
Contributor Author

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.

@sionsmith

Copy link
Copy Markdown
Contributor

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 TestAccUserResource_withExternalIDAndMetadata to fail with an "inconsistent result after apply" error on step 3 (metadata key removal).

We followed up with #19 to fix that — both workos_user and workos_organization now send null for removed metadata keys, which is also included in v2.2.1.

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.

2 participants