feat!: scope coderd_agents_model to organizations - #422
Conversation
c615784 to
34faf9b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34faf9bf48
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 325b4cef3b
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ 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". |
852988f to
123b020
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b11a6a2cb2
ℹ️ 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".
…d route The SDK now calls /api/v2/chats/config/system-prompt, first served in Coder 2.37 (coder/coder#28496). Skip the real-Coder acceptance tests when the deployment does not serve the endpoint, matching the chat model tests.
Coder 2.37 removed GET /api/experimental/chats/models (coder/coder#28632), so organization_id can no longer be recovered from state written by earlier provider versions. Error with re-import instructions instead.
…tion_id State written before models were organization-scoped lacks organization_id, and Coder 2.37 removed the compatibility route that could recover it (coder/coder#28632). Instead of forcing a state rm + re-import, let users set organization_id in config: Read skips refresh on legacy state with a warning, the plan modifier treats null-state adoption as an in-place update rather than a replace, and Update falls back to the planned organization_id, which the org-scoped PATCH verifies and the state write-back records permanently.
Will we bump this again to v2.37.0 after the release? We can wait to release the provider till then or make another release with that change. |
Doesn't make a difference whether its pinned to a commit or a tag fortunately. as long as it has the code we want either is fine |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed6183b993
ℹ️ 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".
An organization_id that is unknown at plan time (e.g. a terraform_data output) conservatively forces replacement, matching the framework's stock RequiresReplaceIfConfigured semantics. Deferring on unknown instead would downgrade a real organization move to an in-place update that PATCHes the old organization. Prove the conservative plan lands correctly end-to-end: the apply deletes the model from the prior organization and recreates it in the resolved one.
|
@codex review re: "Defer replacement while organization ID is unknown" (P1) Intentional — and the suggested deferral would be strictly worse:
|
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ 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". |
Stacked on #422. Coder 2.37 makes the default chat model per-organization rather than deployment-global: each organization has its own default, the first model created in an organization is automatically promoted, and existing configurations are migrated to the default organization. The experimental `coderd_default_agents_model` resource modeled one global selection and no longer matches the server. This PR replaces it with `coderd_agents_default_model`: - Renames the resource from `coderd_default_agents_model` to `coderd_agents_default_model`, grouping it with `coderd_agents_model`. - Requires an explicit `organization_id`; changing it forces replacement. - Uses the organization UUID as the resource `id`, since each organization has one default. - Create and update mark the selected model as default through the organization-scoped `/api/v2` endpoint. - Read lists the organization's models and resolves its current default. - Missing or inaccessible organizations and unsupported Coder versions produce actionable diagnostics. - Delete remains an intentional no-op because Coder requires a default while models exist and provides no unset-default API. ## Breaking change and migration `coderd_default_agents_model` is removed and replaced by `coderd_agents_default_model`. The new resource implements `ResourceWithMoveState`, allowing existing state to migrate declaratively: ```hcl moved { from = coderd_default_agents_model.this to = coderd_agents_default_model.this } resource "coderd_agents_default_model" "this" { organization_id = var.organization_id model_id = coderd_agents_model.default.id } ``` The legacy deployment-wide selection is assigned to the provider's default organization during the move. The configured `organization_id` should therefore identify that same organization. Also folds in the `coderd_agents_mcp_server` import ID change (originally #427): `<organization-name>/<slug>` instead of `<organization-id>/<id>` (the organization component also accepts a UUID). Slugs are unique per organization, but the get-by-ID endpoint only accepts UUIDs, so import resolves the slug from the organization's server list. The resource requires Coder v2.37.0 or later. Its import ID is the organization name (a UUID is also accepted); `model_id` is resolved during read. > Disclosure: Xum (AI agent) authored this PR on @ethanndickson's behalf. Closes CODAGT-973
## Problem All `coderd_*` resources and data sources render on the Terraform Registry with an empty `subcategory`, so the sidebar lists every resource/data source flat with no grouping. ## Fix Add per-resource doc templates under `templates/resources/<name>.md.tmpl` and `templates/data-sources/<name>.md.tmpl` (the [tfplugindocs conventional paths](https://github.com/hashicorp/terraform-plugin-docs#conventional-paths), matching the pattern used by hashicorp/aws, azurerm, google). Each is a copy of tfplugindocs' default template with a hardcoded `subcategory`, grouping pages into: - **Agents** — `agents_mcp_server`, `agents_model`, `agents_system_prompt`, `agents_default_model` - **AI Governance** — `ai_provider` - **Deployment** — `license`, `oauth2_provider_settings`, `provisioner_key`, `workspace_proxy` - **Identity & Access Management** — `organization`, `organization_group_sync`, `organization_sync_settings`, `group`, `user` - **Templates** — `template` The templates also drop the `HasImportIDConfig`/`HasImportIdentityConfig` branches from tfplugindocs' default template: no resource in this repo ships `import-by-string-id.tf`/`import-by-identity.tf` example files, so those branches were always-false dead code. Resource templates keep a single `HasImport` (`terraform import`) section; data-source templates have no import section (data sources are never imported). Regenerated `docs/` with `make gen`; the diff against the base branch is exactly the `subcategory` line per file (19 files), nothing else changed. ## Stacking Stacked on #423 (which stacks on #422). Covers the stack's org-scoped `coderd_agents_default_model` rename (subcategory: Agents); the base already includes the #425 `agents_system_prompt` rename. ## Note for future resources With per-resource templates, a new resource/data source added without a matching `templates/` file falls back to tfplugindocs' embedded default (`subcategory: ""`) and renders uncategorized at the top of the sidebar. Copy a sibling template and set the right subcategory when adding one. ## Testing - `make build`, `make fmt`, and `make gen` (idempotent, no drift) are all clean. - `tfplugindocs validate --provider-name coderd` passes. - `make lint` has 15 pre-existing `usetesting` findings, unchanged from the base (verified via `git stash`); unrelated to this change. --------- Co-authored-by: Ethan Dickson <ethan@coder.com>
Bumps
github.com/coder/coder/v2tov2.34.0-rc.0.0.20260827091847-26b9c8764f91, containing the promoted organization-scoped chat model APIs.Coder 2.37 scopes chat models to organizations and serves the chat API under
/api/v2. The old unscoped model-config API andcodersdk.ChatModelConfigsurface were replaced by organization-scoped chat models under/api/v2/organizations/{organization}/chats/models, and coder/coder#28632 removed the legacy unscoped/api/experimental/chats/modelsroute entirely. This PR adaptscoderd_agents_modelandcoderd_agents_system_promptto the stable/api/v2API, with no experimental-route fallbacks.Breaking changes
coderd_agents_modelandcoderd_agents_system_promptnow require Coder v2.37.0 or later. Against an older server, plans and applies fail with a diagnostic naming the promoted endpoint and minimum version. Downgrade the provider if you need compatibility with older Coder releases.coderd_agents_modelgains anorganization_idattribute. It is optional and defaults to the provider's default organization, where upstream migrated pre-2.37 chat models:Changing a configured
organization_idforces replacement because models cannot move between organizations.The import ID format changes from the model UUID to
<organization-name>/<model-id>(the organization component also accepts a UUID):State written by earlier provider releases has no
organization_id, and the compatibility route that could have recovered it was removed upstream. To upgrade, setorganization_idin config and apply: the provider adopts the model in place (an update, not a replace), verifies the value against the organization-scoped API, and records it in state. Until then, refresh warns and skips, and updates or destroys fail with instructions.What changed
/api/v2endpoints;Readuses GET-by-ID instead of scanning the organization list.organization_idis mapped from server responses and composite imports; legacy state without it is adopted in place from the configured value on the next apply.organization_id) and asserts adoption plans as an in-place update.ghcr.io/coder/coder:latestand development builds can lag the promotion.coderd_default_agents_modelis mechanically adapted to the promoted SDK surface; feat!: add organization-scoped coderd_agents_default_model #423 replaces it with the organization-scopedcoderd_agents_default_modelresource.Stack plan
coderd_agents_modelto organizations and bump the Coder SDK (this PR).coderd_default_agents_modelwithcoderd_agents_default_modelin feat!: add organization-scoped coderd_agents_default_model #423.Relates to CODAGT-973