fix: move coderd_default_agents_model state without a configured provider - #429
Merged
Conversation
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
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…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".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Upgrading from v0.0.23 to v0.0.24 with the documented migration
fails deterministically at plan time:
Terraform Core calls the
MoveResourceStateRPC beforeConfigureProvider(hashicorp/terraform#35922), so the mover'sr.datais always nil — it errored on the nil check and otherwise depended onr.data.DefaultOrganizationIDto fillid/organization_id. Every user of themovedblock hit this; no configuration change could avoid it.Fix
Make the state mover fully offline: carry over only the source state's
model_idand write nullid/organization_id. The first apply then adopts the configured organization in place:Updateresolves the organization viaresolveOrganizationID(prior state, then plan) instead of trusting prior state alone.organization_iduses the shared adoption-friendlyRequiresReplaceIf(replace only when both state and config are non-null), so adoption is an in-place update while genuine org changes still replace.Readwarns and preserves state instead of refreshing whileorganization_idis still null, mirroring the legacy handling incoderd_agents_model.Regression coverage drives the migration through Terraform's real RPC lifecycle: a two-step
resource.Testpersists v0.0.23-schema state with an in-test legacy provider, then plans/applies the dogfood-shaped config (movedblock, 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