Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Terraform Provider v4 to v5 Migration, tf-migrate, and Configuration Rollback

How to move from Terraform provider v4 to v5 with tf-migrate, state upgraders, Grit limits, and rolling back bad applies.

This page summarises Cloudflare documentation on upgrading the Cloudflare Terraform Provider from v4 to v5. People usually land here when terraform plan starts failing after a provider bump, when resource types such as cloudflare_record disappear from the schema, or when they need to undo a bad apply without rebuilding DNS or Access from scratch. The provider renamed many resources and attributes; v5 is now described as production-ready, with tf-migrate and built-in state upgraders intended to cut manual work and avoid unnecessary replacements.

Terraform Provider v5: should you migrate from v4 now?

Section titled “Terraform Provider v5: should you migrate from v4 now?”

Cloudflare’s current position is that Terraform Provider v5 is stable, actively maintained, and the line they want teams on for new capabilities and fixes.

Terraform Provider v5 is stable and actively receiving updates. We encourage all users to migrate to v5 to take advantage of ongoing enhancements and new capabilities.

— Cloudflare, Automate migration from Cloudflare’s Terraform v4 to v5 provider

That message replaced an earlier phase in the same product changelog where Cloudflare asked customers to wait while v5 resources were still being stabilised, and pointed to a dedicated migration tool planned for a later release. If you read older provider release notes (for example Terraform v5.13.0 now available or Terraform v5.15.0 now available), you may still see “hold off on migration” wording; treat the tf-migrate announcement and the consolidated Terraform changelog as the up-to-date migration story unless your resources are not yet covered by automation (see below).

Cloudflare also states that they use tf-migrate on their own infrastructure—the same CLI they ship to customers—which is meant to de-risk the path from v4.

Cloudflare uses tf-migrate to migrate our own infrastructure — the same tool we’re providing to the community — ensuring the best possible migration experience.

— Cloudflare, Automate migration from Cloudflare’s Terraform v4 to v5 provider

v4 to v5 provider changes: resource renames and attribute updates

Section titled “v4 to v5 provider changes: resource renames and attribute updates”

A v4-to-v5 upgrade is not a single-version bump of the same resource types. v5 renames resource types, renames fields, and restructures nested blocks. Documentation calls out examples that break almost every existing stack:

v4 pattern (examples) v5 pattern (examples)
cloudflare_record cloudflare_dns_record
cloudflare_access_application cloudflare_zero_trust_access_application
DNS field value content

The tf-migrate announcement states that 40+ resource types were renamed and that attribute transformations apply across files—not only in the file where the resource is declared.

If you only change the required_providers version without updating HCL and state addresses, terraform plan typically shows destroys and creates even when the remote object in Cloudflare did not change. That is the main reason migrations focus on moved blocks and state alignment, not only on editing .tf files by hand.

tf-migrate: automated v4 to v5 config migration

Section titled “tf-migrate: automated v4 to v5 config migration”

tf-migrate is a purpose-built CLI that Cloudflare introduced to automate the tedious parts of moving from provider v4 to v5.

We’re excited to announce tf-migrate, a purpose-built CLI tool that simplifies migrating from Cloudflare Terraform Provider v4 to v5.

— Cloudflare, Automate migration from Cloudflare’s Terraform v4 to v5 provider

What tf-migrate changes in Terraform configuration

Section titled “What tf-migrate changes in Terraform configuration”

According to Cloudflare, tf-migrate performs these operations:

  • Resource type renames — for example cloudflare_record → cloudflare_dns_record and cloudflare_access_application → cloudflare_zero_trust_access_application, plus many other renames.
  • Attribute transformations — field renames (e.g. value → content for DNS records) and nested block restructuring.
  • moved block generation — creates Terraform 1.8+ moved blocks to avoid resource replacement and support zero-downtime migration where the provider allows it.
  • Cross-file reference updates — updates references to renamed resources across the whole configuration tree.
  • Dry-run mode — preview changes before writing them to disk.

Combined with the automatic state upgraders introduced in v5.19+, tf-migrate eliminates the manual work and risk that previously made v5 migrations challenging. Tf-migrate operates directly on the config, and the built-in state upgraders handle the rest.

— Cloudflare, Automate migration from Cloudflare’s Terraform v4 to v5 provider

In practice: run tf-migrate on configuration first, then run terraform plan with provider v5.19+ so state upgraders can finish what the CLI does not touch. Skipping either step is a common source of unexpected replacements.

tf-migrate coverage limits and manual follow-up

Section titled “tf-migrate coverage limits and manual follow-up”

tf-migrate does not claim full coverage of every v4 resource on day one. Cloudflare prioritises the most common customer resources and expands support over time.

Tf-migrate currently supports the most common Terraform resources our customers use. We are actively working to expand coverage, with the most commonly used resources prioritized first.

— Cloudflare, Automate migration from Cloudflare’s Terraform v4 to v5 provider

Resources that tf-migrate does not yet handle must be migrated manually using Cloudflare’s version 5 upgrade guidance (linked from the same announcement and Terraform product changelog as the Version 5 Migration Guide and v5 Stabilization Tracker). The tracker is the place to see per-resource migration status as stabilisation work continues.

Grit migration scripts: earlier automation and Terraform modules gap

Section titled “Grit migration scripts: earlier automation and Terraform modules gap”

Before tf-migrate, Cloudflare documented Grit-based automated migration scripts for teams evaluating v4 → v5. That guidance appears across multiple provider release posts and the Terraform changelog, for example:

If you are evaluating a move from v4 to v5, please make use of the migration guide ↗︎. We have provided automated migration scripts using Grit which simplify the transition, although these do not support implementations which use Terraform modules, so customers making use of modules need to migrate manually.

— Cloudflare, Terraform v5.4.0 now available

The important limitation repeated in those entries: Grit scripts do not support configurations that use Terraform modules. Module-based layouts were expected to migrate manually and still rely on terraform plan before apply. If the layout uses shared modules, prefer tf-migrate where supported, or manual steps from the upgrade guide; do not assume a Grit codemod rewrote module sources.

Cloudflare’s broader SDK ecosystem support policy matches this pattern for major upgrades: automated codemods where possible, plus written documentation for manual edits when automation does not reach your layout.

Where possible, Cloudflare provides an automated approach to performing major version upgrades to limit the disruption using codemods. Review the library or tool-specific release notes for how to use these migration tools.

— Cloudflare, SDK ecosystem support policy

v5 SDK tutorials and rolling back configuration (revert workflow)

Section titled “v5 SDK tutorials and rolling back configuration (revert workflow)”

Cloudflare’s Terraform tutorials note that post-migration HCL targets the v5 SDK only. After you move to v5, day-two operations include rolling back bad changes—not only forward migrations.

Sometimes, you may have to roll back configuration changes. For example, you might want to run performance tests on a new configuration or maybe you mistyped an IP address and brought your entire site down.

— Cloudflare, 6 – Revert configuration

The revert configuration tutorial describes checking out the desired Git branch and using Terraform to move Cloudflare settings back to a known-good revision—Git history as the source of truth for infrastructure intent. That is separate from tf-migrate (which rewrites provider syntax) but equally important when a v5 apply takes production down. Cloudflare also suggests peer review on pull requests instead of merging directly to a production branch, which the tutorials simplify for brevity.

  • Applying provider v5 without renaming resources or without moved blocks, then accepting destroy/create plans.
  • Running automation (Grit or tf-migrate) on a dirty Git tree; fix or stash changes first (the same discipline applies to other Cloudflare codemods such as Wrangler migrate, which errors when the worktree is not clean).
  • Assuming module-heavy layouts were rewritten by Grit scripts—they were explicitly out of scope in provider upgrade notes.
  • Skipping terraform plan after migration; Cloudflare repeatedly asks users to plan before apply and report issues via their GitHub repository or support ticket (see Terraform v5.4.0 now available).
  • Ignoring tf-migrate dry-run output and writing breaking changes blindly.
  1. On a branch, run tf-migrate in dry-run mode and review renames, attribute changes, and generated moved blocks against the behaviour described in Automate migration from Cloudflare’s Terraform v4 to v5 provider.
  2. Cross-check every resource type you manage with stabilisation and tf-migrate support information linked from the Terraform product changelog and the tf-migrate post (unsupported types need manual steps from the version 5 upgrade guide).
  3. Pin the Cloudflare provider to v5.19+ (or newer) so automatic state upgraders can run, then execute terraform plan and confirm the plan shows updates or no-ops—not unintended replacements—for production-critical resources.
  4. If the plan is wrong after a bad apply, follow 6 – Revert configuration: check out the last known-good commit on a reviewed branch and plan/apply rollback before touching live DNS or Access settings again.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match Cloudflare’s current provider docs, email yimasynthetic@gmail.com with the page URL and the exact statement you think is wrong or unclear.