fix: refresh entitlements after license create/delete#306
fix: refresh entitlements after license create/delete#306ethanndickson merged 2 commits intomainfrom
Conversation
After adding or removing a license, the provider now re-fetches deployment entitlements so that resources created later in the same terraform apply (e.g. coderd_workspace_proxy with depends_on) see up-to-date feature flags instead of the stale snapshot from provider configuration. The refresh is best-effort: if re-fetching entitlements fails, a warning is emitted but the license operation itself still succeeds. Adds a regression acceptance test that creates a license and workspace proxy in a single apply to verify the fix. Closes #303
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a347067e8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Follow-up (previous comment had markdown formatting issues in shell): Addressed the last Codex comment about unsynchronized shared feature cache updates in Implemented in
This keeps entitlement cache updates and reads race-safe under Terraform parallelism. @codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
When deploying a
coderd_workspace_proxy(or other entitlement-gated resource) immediately aftercoderd_licensein the sameterraform apply, the proxy creation fails with:This happens because the provider fetches entitlements once during
Configure()(before any resources are created) and never refreshes them. Aftercoderd_licenseadds the license to the server, subsequent resources still see the stale pre-license feature flags.Fix
After
LicenseResource.Create()and.Delete()succeed, re-fetch deployment entitlements and update the sharedCoderdProviderData.Featuresmap. Since all resources share the same pointer, they immediately see up-to-date entitlements.The refresh is best-effort: if re-fetching entitlements fails, a warning is emitted but the license operation itself still succeeds.
Regression test
Adds
TestAccWorkspaceProxyResourceAfterLicenseInSameApplywhich starts an unlicensed Coder instance and applies a config that creates bothcoderd_licenseandcoderd_workspace_proxy(withdepends_on) in a single step — the exact scenario from the bug report.Closes #303