Back to Terraform

Provider Migration Deep Dive: State Upgraders, Renames and Splits

November 6, 2026 Wasil Zafar 23 min read

Evaluate an actual v4-to-v5 change set instead of assuming a migration tool guarantees a no-change apply

Table of Contents

  1. Build a Resource-by-Resource Migration Ledger
  2. Normalize Legacy State Only Through a Reviewed Supported Workflow
  3. Review Automated Config Changes and Moved Instructions
  4. Distinguish Normalization from Real New Resource Creation
  5. Accept the Migration on Runtime and Ownership Evidence

Build a Resource-by-Resource Migration Ledger

A provider upgrade is a version bump; a migration is a set of per-object decisions. The release decides which mechanisms exist, and the ledger decides which mechanism each object receives. Terraform 1.17.1 and cloudflare 5.28.1 belong in the header of that document, not only in a commit message.

Three layers move independently, and each one fails differently. The configuration text describes the v5 schema, the address names the object inside state, and the stored record holds the identifier the provider calls. A rewritten file can be valid while the address still reads cloudflare_record and the record still carries a v4 schema version.

Sort objects by change type before you sort them by file. Four categories cover almost everything: arguments only, type rename, split or merge, and a manual gap the tool refuses to guess. The sort tells you how many distinct rehearsals you need, which is usually fewer than the number of files.

Put the tool's validated range next to the versions you pinned. tf-migrate publishes a matrix pairing a v4 source range with a target release, and our target sits beyond its last validated column. That does not block the work, but the ledger must record "unvalidated target" instead of borrowing a green tick from an older release.

Every row needs an owner and an evidence link. The owner is the team allowed to approve a behavior change. The evidence is a saved plan, a probe transcript or an id comparison that a reviewer can open without rerunning anything.

A row closes on evidence, not on intention. Keep the ledger in the repository beside the root module, so the migration produces a reviewable diff of its own rather than a story in a chat thread.

Build a Resource-by-Resource Migration Ledger
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Object in the v4 root"] --> B{"What changes?"}
    B -->|"arguments only"| C["Rewrite the block: same address, same id"]
    B -->|"type or address"| D{"Move handler for this type?"}
    B -->|"one object becomes two"| E["Split: one primary, one companion"]
    D -->|"yes"| F["moved block: state follows on apply"]
    D -->|"no"| G["Removal with destroy disabled, then import"]
    E --> H["Import the companion with its own identifier"]
    C --> I["Ledger row plus runtime evidence"]
    F --> I
    G --> I
    H --> I
    I --> J{"Every plan line explained?"}
    J -->|"no"| B
    J -->|"yes"| K["Row approved by its owner"]
    classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
    classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
    classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
    classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
    classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
    class A,D,J primary;
    class B,E secondary;
    class C,F,G,H,I,K ok;
    class J warn;

The branch that matters is the move-handler question: everything else is either a text edit or a fresh import.

Three layers bound by one ledger row Configuration text, resource address and stored state change independently. A single ledger row binds all three to one owner and one piece of evidence, which is what a reviewer approves. Three layers, bound by one row Configuration text arguments, blocks, types read by the v5 schema changed by a rewrite reviewed as a normal diff fails as a validation error Resource address type and name in state what moved and import target changed by a move kept until every workspace applies fails as create plus destroy Stored state record provider id, schema version decoded by the provider changed by an apply never by a text editor fails as a load error One ledger row: old address, new address, state action, config change plus the owner who can approve the change and the evidence that closes it. A version bump touches none of these. Only an apply writes the record. A green plan is not a row. An id comparison plus a probe is a row.
Address changeState actionConfiguration changeOwnerEvidence
cloudflare_record.www to cloudflare_dns_record.wwwmoved block, provider move handlervalue to content, zone to zone_idEdge teamSame record id, move annotation in the plan
cloudflare_zone_settings_override.edge to one cloudflare_zone_setting.* per settingRemoval with destroy disabled, then one import per settingBlock deleted, one resource per settingPlatformOne composite id per setting, settings read back unchanged
cloudflare_workers_secret.api to a binding in cloudflare_workers_script.apiMerge, then script updatesecret_text binding, value from the secret storeWorkersScript version deployed, secret resolves at runtime
cloudflare_access_policy.office to cloudflare_zero_trust_access_policy.officemoved block plus scope checkZone id dropped, account id addedSecurityPolicy list on the app, allow and deny probes
cloudflare_ruleset.edgeNone, in-place upgradeRuleset block shapeEdge teamSame ruleset id, the blocked request is still blocked

The last row is the quiet one. A ruleset that keeps its address still passes through the provider's state upgrader, and a failed upgrade surfaces as a plan error rather than a rename. Give it a row even when the type did not change.

Write the state action as a verb with an object. Move and import are different operations with different failure modes, and the word migrate hides which one you chose. Each row should read like an instruction a second engineer could execute without asking you.

Rows with a manual gap decide the schedule. The automatic paths are quick and the manual ones carry the review, so plan the window around the entries that need a human, not around the majority that do not.

Normalize Legacy State Only Through a Reviewed Supported Workflow

State has a format version, and a provider refuses formats it cannot decode. A document written before Terraform 0.12 stores flat attribute maps; the v5 provider cannot read them and returns an error that looks like corruption. The check is a read, not a migration.

Inspect a copy, never the original. Pull the state to a scratch file and read its lineage, serial and per-resource schema version. Those fields are the concurrency contract, and none of them should change because an editor was open.

Hand-editing JSON is tempting because the file is readable. The same document holds secret values in plaintext, a provider-private blob and the counters that keep two applies from overwriting each other. An edit can produce valid JSON and still be wrong in all three dimensions.

The upgrade happens when Terraform loads the record, not at init. If a stored schema version is older than the provider's current version, the provider's upgrader converts it in memory. The converted shape becomes durable only when Terraform writes state after a refresh or an apply.

A discarded plan is not a normalized state. Terraform normally writes refreshed state back to the backend, but a plan you never apply, or a backend that rejects the write, can leave the file at the old schema version. The conversion is then repeated on the next run rather than lost.

The schema version belongs to the record, not the provider. Two instances of the same type in one state can carry different versions if an older release wrote one of them. That is why a single plan can upgrade some records and fail on one, and why the ledger tracks the id per instance rather than per type.

One failed upgrade fails the plan, not just the record. Terraform reports the error and stops before proposing changes for anything else in the root, so one unsupported type blocks the whole run. Rehearse the oldest record first for exactly that reason.

The intermediate form matters more than the version number. The 4.52.5 release writes the transitional shape that later upgraders expect; jumping straight from an older v4 leaves the upgrader reading a form it never handled. The floor is a functional requirement, not paperwork.

The supported normalizers are three primitives. A move changes the address, an import adopts an existing object, and a removal drops an address without touching the object. All three are configuration, all three are reviewed, and all three preserve the provider's private data.

Prefer a removal block to a shell command. The removal with destroy disabled is applied by the pipeline, appears in the run history and needs no backend credentials. A direct state removal is acceptable only when the workspace is local and you accept it is unaudited.

Give every state write a witness. Capture the serial before and after, plus the ids of the objects involved. A write that cannot show both is a write nobody can review later.

Normalize Legacy State Only Through a Reviewed Supported Workflow
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Read a copy of the stored state"] --> B{"Flat attribute keys present?"}
    B -->|"yes"| B1["Stop: upgrade through v4.52.5 first"]
    B -->|"no"| C["Compare schema version per resource"]
    C --> D{"Stored version newer than the provider?"}
    D -->|"yes"| D1["Stop: wrong provider or edited state"]
    D -->|"no"| E{"Upgrader exists for this type?"}
    E -->|"yes"| F["Load the record and convert it in memory"]
    E -->|"no"| G["Read against the v5 schema, expect a diff"]
    F --> H["Refresh or apply writes the new shape"]
    G --> H
    H --> I{"Serial and lineage intact?"}
    I -->|"no"| I1["Stop: the state was replaced, not upgraded"]
    I -->|"yes"| J["Record id and schema version in the ledger"]
    classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
    classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
    classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
    classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
    classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
    class A,C,E,I primary;
    class F,H,J ok;
    class B,D,G warn;
    class B1,D1,I1 danger;

A lineage mismatch is a stop sign, not an obstacle. A push against a different lineage means you are writing into a state file that another workspace owns. Forcing it is how two teams discover, weeks later, that they traded objects.

A stored version ahead of the provider is worse than a missing upgrader. It usually means a hand edit or a downgrade, and the provider has no path back. Rebuild that record from the API and the configuration rather than editing the number down.

Keep normalization inside its documented boundary. Precedence collapsing, a CIDR losing its prefix length and empty values becoming null are known representation changes. A changed hostname or a dropped rule is not normalization, whatever the diff label says.

Review Automated Config Changes and Moved Instructions

Pin the tool and state both ends of the rewrite. The migrator takes a source and a target version, and its default target is whichever release it can find. Pass both explicitly, record the binary version, and treat the pair as part of the change record.

A dry run is only useful if you read the diff. The dry run prints the rewrite without writing files. Save that output, then run the real migration into a separate output directory so the original tree stays diffable against the result.

Read the diff in three passes: types, addresses, references. Type and attribute renames are mechanical and easy to verify. Address changes are move and import blocks, where a wrong destination is expensive. References are the cross-file edits that a compiler would catch and Terraform will not.

Moved instructions outlive the pull request. The block runs during plan and apply, after which the state holds the new address. Other workspaces and open branches still need the instruction, so delete it only when the ledger says every consumer has applied.

Move blocks cross module boundaries, which is where they break. Both addresses include the module path, so a resource that also changes module needs both halves corrected. A move that fixes only the type leaves the old path in state and produces a create beside an orphan.

Generated import blocks are one-shot instructions. Each names a destination address and an identifier, applies once and must then be removed; left in place, it makes the next plan complain that the object is already managed. The ledger records that removal as part of the row.

Every migration warning is an open ledger row. The tool writes the comment exactly where it could not infer a required value, and those fields either fail the apply or take a silent default. Grep for them, then resolve each one by hand.

Part of the rewrite is a workaround, not a rename. The zone-settings path is phased: the tool comments out the old resource, appends a removal and asks you to apply with the old provider before completing. That two-run sequence is the vendor's supported route, and collapsing it into one apply is how a split lands in the wrong order.

Second-order consumers live outside the directory. Roots that read remote state, jobs that parse plan output and dashboards keyed on resource addresses break quietly after a clean rewrite. Add them to the ledger as consumers, not as resources.

Where the tool stops and judgement starts The migration tool owns the configuration text, the provider owns the stored record at load time, and the team owns the decision to accept. Assumptions that cross those boundaries are the expensive ones. Three owners, three boundaries Migration tool owns the files renames types and arguments writes move and import blocks stops at the last semicolon Provider owns the record converts it at load time moves it when a handler exists stops at the schema version Your team owns the decision accepts the values compares runtime probes stops at the evidence Assumption one: the rename table is complete It is complete for the resources the tool tested. Your resources are the ones that were not in the test. Assumption two: a clean plan means the migration is finished the plan never saw a browser Boundaries are not obstacles. They tell you which question each owner is allowed to answer.

Assign each hunk to a reviewer, not to the tool. A rename that only changes a type can be reviewed by reading the diff. An import block needs someone who knows the live object, because the plan cannot tell you whether the identifier points at the right one.

Accept the rewrite in slices. Limiting a run to named resource types lets one pull request carry DNS and the next carry the ruleset. Smaller slices keep each move block's lifetime short and make a rollback a revert rather than a surgery.

The lock file is part of the configuration. Regenerating it is what makes the pipeline download v5; a committed lock file still holding v4 hashes produces a schema error even when the constraint says otherwise. Commit the file with the rewritten configuration, in the same change.

Distinguish Normalization from Real New Resource Creation

The provider identifier is the test. The same id before and after means the object was moved or normalized. A different id means Terraform created something, whatever the plan summary chooses to call it.

Normalization rewrites a representation, and the list is short. Precedence collapses to a user-facing value, a CIDR loses its prefix length, and empty strings, maps and lists become null. Accept those after confirming the resulting value is the one you intended.

A split creates an address that never had state. The v4 object was one record; each new resource needs its own import with the documented identifier. If Terraform creates them instead, it writes configuration values into live settings rather than reading what is already there.

The identifier shape is part of the split. A zone-scoped setting combines the zone and the setting name in one reference, while an account-scoped object takes an account id. Guessing the shape either imports the wrong object or fails with a 404 that reads like a permissions problem.

Order the split inside a single apply where the provider allows it. A removal with destroy disabled and an import of the companion can share one plan, so the old address leaves state in the same run that the new address enters it. Rehearse the order, because a failed import leaves that address unmanaged until the next run.

A split with two destinations has only one state record. Smart routing and tiered caching are the Argo case: two addresses for behavior that one v4 resource owned. Only one address can inherit the record, so the companion is imported, and both must be in the plan before the old address is removed.

A merge can demand a secret rather than an address. Worker secrets fold into the script as bindings. The value is write-only, so the merge reads it from the secret store and produces a real script update — a configuration change with a dependency, not a bookkeeping move.

Read replacements by reason, never by count. A scope change, a ForceNew argument and a missing move all render with the same marker. The first two can be correct; the third means the address was never moved, and applying it destroys the object you meant to keep.

One create is legitimate: the split companion. The companion is new state for existing behavior, so the check is that the live setting did not change during the apply. Capture it before and after, and treat a changed value as configuration winning over reality.

Same id normalizes, new id creates Compare the provider identifier before and after a plan. An unchanged id means the record was moved or normalized and only its values need checking. A new id means a create call, which is correct for a split companion and wrong for a rename. The identifier decides the category Before the apply record the provider id per address After the plan compare the two ids Same id? then nothing was created same id new id Moved or normalized: accept with a value check Precedence, CIDR prefix length, empty to null The object keeps its identity and its behavior Evidence: same id, same probe result Created: import it, or accept a real create A split companion is the legitimate case A rename that lands here never moved Evidence: live setting unchanged after apply Same id, different value A real behavior change hiding in a rename. Stop and explain it before the window closes. New id on a rename The move block was missing, wrong or unapplied. Fix the address. Do not accept the replacement. Replacement is the third case: same address, new id, and a destroy that runs first.

Count ids, not resources. A split raises the resource count and a merge lowers it, so the totals prove nothing. The mapping between old and new addresses is the artifact a reviewer can check.

Zone settings have no delete, which changes the risk. Dropping the override from state stops management; it does not switch anything off. A created setting resource, by contrast, writes a value into the zone, which is why the import path is the safer default.

A computed field that resolves is not a create. Timestamps, versions and generated metadata reappear after a refresh with a known value. Their newness is a read, not a new object, and the id comparison keeps that distinction honest.

Accept the Migration on Runtime and Ownership Evidence

A clean plan is a claim about records. It says configuration, state and the provider's read model agree. It says nothing about whether a hostname resolves, a certificate chain is complete or a rule still blocks the request it blocked yesterday.

Ownership evidence is a one-to-one mapping. Every old address resolves to exactly one new address, or to a documented removal. Orphans are what a clean plan hides, because an object nobody manages produces no diff until someone writes over it.

Diff the state list, not the plan. Listing addresses before and after exposes orphans and duplicates in one comparison, including addresses that no configuration declares any more. The plan cannot show what it never read.

Runtime evidence is the baseline, repeated. The same DNS answer from the authoritative and a public resolver, the same certificate chain and minimum version, the same blocked request and the same allowed one, the same Worker route body. Same probes, same order, same vantage points.

Both gates must pass inside one window. Matching ids with a changed TLS default is a regression. Matching probes with an orphaned address is a duplicate waiting for the next apply. Accepting one gate and not the other is how a migration gets reopened a month later.

Rollback is part of acceptance, not a contingency. The old branch, the old lock file and the state snapshot are the rollback, and the snapshot is the only one that survives a v5 rewrite. Once the record is upgraded, an older provider may refuse to read it.

Name the perpetual differences while you still remember them. A few attributes will keep reappearing as changes, usually computed values the API does not return. Record them with a reason in the ledger, so the next engineer does not reopen the migration over a known difference.

Deep Dive

Approve a rehearsed migration

Execution status: design-only. This is a rehearsal on copies. No production state, configuration or Cloudflare object is touched. The pinned pair is Terraform CLI 1.17.1 and cloudflare/cloudflare 5.28.1, with the migration tool release recorded in the change record.

Prerequisites. A root that manages at least one DNS record, one ruleset, one zone setting and one Worker route; a read-only API token; a state snapshot; and a rehearsal directory seeded from that snapshot.

Baseline capture. Record these before the rewrite, from the same machine and network.

ProbeCapturePass condition after migration
DNSAnswer from the authoritative nameserver and a public resolver, plus proxy statusIdentical answer and proxy status
TLSCertificate chain, minimum version, HSTS header at the edgeIdentical chain and version
RulesetOne request that must be blocked, one that must passSame status codes and headers
WorkerRoute response body and response headersIdentical body and headers
OwnershipProvider id per address from the stateOne old address maps to one new address

Procedure.

  1. Build the ledger rows for the selected objects and mark each one automatic, manual or split.
  2. Run the migration tool with a dry run into a saved file, then for real into a separate output directory.
  3. Review the diff in three passes: types, addresses, references. Resolve every migration warning.
  4. Seed a scratch workspace from the snapshot, point the provider constraint at 5.28.1 and regenerate the lock file.
  5. Plan to a saved file, then compare each line's id with the ledger. Stop on any create for a renamed address.
  6. Apply only the reviewed plan, then repeat every baseline probe in the same order.
  7. Re-plan and confirm the only remaining differences are the documented one-time refreshes.

Expected observation. Renamed objects keep their ids, split companions appear as imports with composite identifiers, no destroy appears for an address you meant to keep, and the five probes return the same results as the baseline.

Failure check. A record with a new id means the move never ran. A policy that loads without a challenge means inline policies were dropped in the merge. A missing certificate or a different minimum version means a zone setting was created rather than imported.

Cost and cleanup. API reads, a handful of plans and one apply against a copy. Delete the rehearsal directory and saved plans; keep the state snapshot and the ledger until the change record closes.

Close the row, then close the window. The provider version is the mechanism, the plan is the claim, and the id mapping plus the repeated probes are the evidence. A migration is finished when all three agree — not when the tool exits zero.