Skip to content

fix: refresh entitlements after license create/delete#306

Merged
ethanndickson merged 2 commits intomainfrom
license-cache-7374
Feb 25, 2026
Merged

fix: refresh entitlements after license create/delete#306
ethanndickson merged 2 commits intomainfrom
license-cache-7374

Conversation

@ethanndickson
Copy link
Member

Problem

When deploying a coderd_workspace_proxy (or other entitlement-gated resource) immediately after coderd_license in the same terraform apply, the proxy creation fails with:

Error: Feature not enabled

Your license is not entitled to create workspace proxies.

This happens because the provider fetches entitlements once during Configure() (before any resources are created) and never refreshes them. After coderd_license adds 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 shared CoderdProviderData.Features map. 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 TestAccWorkspaceProxyResourceAfterLicenseInSameApply which starts an unlicensed Coder instance and applies a config that creates both coderd_license and coderd_workspace_proxy (with depends_on) in a single step — the exact scenario from the bug report.

Closes #303

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
@ethanndickson
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@ethanndickson
Copy link
Member Author

Follow-up (previous comment had markdown formatting issues in shell):

Addressed the last Codex comment about unsynchronized shared feature cache updates in CoderdProviderData.

Implemented in fc2a6d6:

  • Replaced mutable Features map field with an atomic snapshot (atomic.Pointer[featureSnapshot]) in CoderdProviderData.
  • Added SetFeatures, Features(), and FeatureEnabled methods.
  • Updated license create/delete refresh paths to call SetFeatures(...) instead of writing shared state directly.
  • Updated entitlement read call sites (workspace_proxy, group resource/data source, and template) to read through the atomic accessors.

This keeps entitlement cache updates and reads race-safe under Terraform parallelism.

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Hooray!

ℹ️ 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".

@ethanndickson ethanndickson merged commit acad6da into main Feb 25, 2026
13 checks passed
@ethanndickson ethanndickson deleted the license-cache-7374 branch February 25, 2026 02:19
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.

coderd_license doesn't apply in time

2 participants