Skip to content

fix: move coderd_default_agents_model state without a configured provider - #429

Merged
ethanndickson merged 2 commits into
mainfrom
state-mover-wt54
Aug 31, 2026
Merged

fix: move coderd_default_agents_model state without a configured provider#429
ethanndickson merged 2 commits into
mainfrom
state-mover-wt54

Conversation

@ethanndickson

Copy link
Copy Markdown
Member

Problem

Upgrading from v0.0.23 to v0.0.24 with the documented migration

moved {
  from = coderd_default_agents_model.this
  to   = coderd_agents_default_model.this
}

fails deterministically at plan time:

Error: Unable to Move Default Agents Model State
The provider was not configured before Terraform attempted to move coderd_default_agents_model state.

Terraform Core calls the MoveResourceState RPC before ConfigureProvider (hashicorp/terraform#35922), so the mover's r.data is always nil — it errored on the nil check and otherwise depended on r.data.DefaultOrganizationID to fill id/organization_id. Every user of the moved block hit this; no configuration change could avoid it.

Fix

Make the state mover fully offline: carry over only the source state's model_id and write null id/organization_id. The first apply then adopts the configured organization in place:

  • Update resolves the organization via resolveOrganizationID (prior state, then plan) instead of trusting prior state alone.
  • organization_id uses the shared adoption-friendly RequiresReplaceIf (replace only when both state and config are non-null), so adoption is an in-place update while genuine org changes still replace.
  • Read warns and preserves state instead of refreshing while organization_id is still null, mirroring the legacy handling in coderd_agents_model.

Regression coverage drives the migration through Terraform's real RPC lifecycle: a two-step resource.Test persists v0.0.23-schema state with an in-test legacy provider, then plans/applies the dogfood-shaped config (moved block, org data source) against the real provider factories, asserting in-place updates and final state. With the fix reverted, the test reproduces the dogfood error verbatim. Also records the lesson in AGENTS.md.

Refs coder/dogfood#453

Terraform Core calls the MoveResourceState RPC before ConfigureProvider
(hashicorp/terraform#35922), so the coderd_default_agents_model ->
coderd_agents_default_model mover always saw nil provider data and
failed every plan using the moved block with "The provider was not
configured before Terraform attempted to move ... state".

The mover now carries over only the source state's model_id and writes
null id/organization_id; the first apply adopts the configured
organization in place via resolveOrganizationID, an adoption-friendly
RequiresReplaceIf on organization_id, and a Read that warns and
preserves state instead of refreshing when the organization is unknown.

Regression coverage drives the migration through Terraform's real RPC
lifecycle: a two-step resource.Test persists v0.0.23-schema state with
an in-test legacy provider, then plans/applies the moved block against
the real provider factories, asserting in-place updates and final
state. With the fix reverted, the test reproduces the dogfood failure
verbatim.

Refs coder/dogfood#453
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T11:52:03.532221Z bbc265e PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ethanndickson ethanndickson changed the title fix(coderd_agents_default_model): make MoveState mover offline fix: move coderd_default_agents_model state without a configured provider Aug 31, 2026
…low Terraform 1.8

Cross-resource-type moved blocks (the MoveResourceState RPC) were added in Terraform 1.8, so TF 1.5-1.7 in the CI matrix rejected the test's moved block with "Resource type mismatch".
@ethanndickson
ethanndickson merged commit cd90960 into main Aug 31, 2026
13 checks passed
@ethanndickson
ethanndickson deleted the state-mover-wt54 branch August 31, 2026 11:59
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.

1 participant