Terraform v5 State Migration, Drift and Resource Stabilization
How to move from Terraform provider v4 to v5, fix perpetual plan drift, and handle breaking changes, deprecations, and stabilized resources.
This page summarizes Cloudflare Terraform provider release notes and migration-related changelog entries. The material is aimed at operators who manage Cloudflare with Terraform and see unexpected terraform plan output, need to upgrade major provider versions, or want to know which resources are considered stable on v5.
Terraform provider v5: what changed at a glance
Section titled “Terraform provider v5: what changed at a glance”Cloudflare’s Terraform provider v5 is built on the Plugin Framework and ships with broad state upgraders, drift fixes, and waves of resource stabilization. Release notes repeat three practical themes: migrate existing state from v4 without rewriting every resource block, stop “permanent diff” behavior where the API and schema disagree, and expand import support and new resources (Workers, Zero Trust, Magic WAN, and others).
Older v4 resources often remain in configuration during upgrade; the provider rewrites stored state through state upgraders rather than forcing an immediate destroy-and-recreate for every affected object—though you should still read breaking-change notices before upgrading production stacks.
v4 to v5 migration: state upgraders and schema versions
Section titled “v4 to v5 migration: state upgraders and schema versions”Which resources get automatic v4→v5 state upgraders
Section titled “Which resources get automatic v4→v5 state upgraders”Cloudflare documents state upgraders added for seamless migration from v4 to v5 for a defined set of resources, including account-level and Zero Trust objects:
State upgraders added for seamless migration from v4 to v5 for the following resources:
account, account_member, account_token, authenticated_origin_pulls, authenticated_origin_pulls_hostname_certificate, byo_ip_prefix, custom_hostname, custom_ssl, leaked_credential_check, leaked_credential_check_rule, logpush_ownership_challenge, mtls_certificate, observatory_scheduled_test, pages_domain, regional_tiered_cache, turnstile_widget, workers_custom_domain, zero_trust_device_custom_profile, zero_trust_device_default_profile, zero_trust_device_posture_integration, zero_trust_gateway_certificate, zero_trust_gateway_settings, zero_trust_organization, zero_trust_tunnel_cloudflared_virtual_network, zone_setting
— Cloudflare, Terraform v5.19.0 now available
After you bump the provider constraint and run terraform plan, Terraform should run these upgraders against matching resources in state. If plan fails with migration or nil-pointer errors tied to a specific resource, check the same release’s Migration & State Management section—for example fixes for ambiguous schema_version when v4 and v5 coexist, or zero_trust_access_policy state upgrader panics (Terraform v5.19.0 now available).
Broader migration machinery (SDKv2 to Framework)
Section titled “Broader migration machinery (SDKv2 to Framework)”Separately from the v4→v5 list above, changelogs describe state upgraders to 95+ resources to prepare for replacing Grit (noted as still under active development), plus per-resource handlers—for example dns_record, certificate_pack, load_balancer_pool (with detection for v4 vs v5 format), pages_project, and tiered_cache (Terraform v5.17.0 now available).
New resources are aligned on a common schema baseline:
set initial schema version to 500 for all new resources
— Cloudflare, Changelog
Documentation updates also point operators at application-scoped access policy migration guidance and an updated zone_settings_override migration guide for tf-migrate v2 workflow (Terraform v5.19.0 now available).
terraform plan drift: why configuration “changes” every run
Section titled “terraform plan drift: why configuration “changes” every run”API shape vs Terraform schema
Section titled “API shape vs Terraform schema”Most v5.x patch releases are drift-oriented: the Cloudflare API returns fields Terraform previously treated as unknown, empty, or differently typed, so terraform plan shows updates you did not author. Changelogs describe provider-side mitigations such as UseStateForUnknown, preserving prior state for optional fields not returned by the API, normalizing empty nested objects, and correcting wrong ID fields in API calls (Terraform v5.19.0 now available, Terraform v5.17.0 now available).
Representative problem areas called out across releases:
| Area | Typical symptom | Direction in release notes |
|---|---|---|
| Zero Trust Access / Gateway | Perpetual diff on apps, policies, identity providers, tunnel routes | Serialization fixes, OIDC claims support, filters marked Computed+Optional (Terraform v5.7.0, Terraform v5.5.0) |
cloudflare_workers_script |
Drift with unmanaged secrets, migrations treated as write-only, Assets defaults | Secret drift resolution; migrations no longer WriteOnly (Terraform v5.14.0) |
| DNS / rules / tokens | Record normalization, ruleset refresh, token policy order | FQDN normalization fixes; chronic drift on cloudflare_ruleset and cloudflare_api_token (Changelog, Terraform v5.8.2) |
| Lists and load balancers | IP list validation, session_affinity_ttl type mismatch |
Validators and type expectations aligned after migration (Terraform v5.16.0) |
A cross-cutting note in migration releases:
drift: Preserve prior state values for optional fields not returned by API
— Cloudflare, Terraform v5.19.0 now available
Upgrading to the newest patch release for your major line often removes class-wide drift without Terraform configuration changes.
“Resources stabilized”: what that means for you
Section titled ““Resources stabilized”: what that means for you”Several posts announce batches of Resources stabilized—for example early tranches including cloudflare_zone_setting, cloudflare_worker_script, cloudflare_worker_route, and tiered_cache (Terraform v5.9 now available), later tranches adding Zero Trust Access resources, load balancers, snippets, and cloudflare_zone (Terraform v5.8.4), and cloudflare_dns_record, cloudflare_page_rule, and related cache resources (Terraform v5.8.2).
In practice, stabilized means the provider maintainers consider schema, refresh, and migration behavior production-ready for those resources—not that drift is impossible forever. You should still run plan after upgrade; stabilization releases often bundle targeted diff fixes (for example cloudflare_bot_management diff issues resolves when running terraform plan and terraform apply in Terraform v5.8.4).
Breaking changes, removals, and renames
Section titled “Breaking changes, removals, and renames”API and account token policy ordering
Section titled “API and account token policy ordering”Please be aware that there are breaking changes for the cloudflare_api_token and cloudflare_account_token resources. These changes eliminate configuration drift caused by policy ordering differences in the Cloudflare API.
— Cloudflare, Terraform v5.13.0 now available
The same release adds api_token+account_tokens: state upgrader and schema bump (Terraform v5.13.0 now available). Expect a one-time plan that may reorder or normalize policy blocks in state; read the repository changelog linked from that post before applying in CI.
Snippets: cloudflare_snippets deprecated
Section titled “Snippets: cloudflare_snippets deprecated”NEW resource cloudflare_snippet which should be used in place of cloudflare_snippets. cloudflare_snippets is now deprecated. This enables the management of Cloudflare’s snippet functionality through Terraform.
— Cloudflare, Terraform v5.9 now available
New work should target cloudflare_snippet and cloudflare_snippet_rules; later releases mention Multipart handling restored for cloudflare_snippet (Terraform v5.8.4).
Removed worker_platforms_script_secret
Section titled “Removed worker_platforms_script_secret”Removes the worker_platforms_script_secret resource from the provider (see migration guide ↗︎ for alternatives—applicable to both Workers and Workers for Platforms)
— Cloudflare, Terraform v5.4.0 now available
If state still references that resource, upgrade planning must include removing or replacing those blocks; the v5.4.0 post is the authoritative notice in this cluster.
Field and endpoint shifts worth tracking
Section titled “Field and endpoint shifts worth tracking”Examples from recent feature releases:
zero_trust_dlp_predefined_profile: switch of DLP Predefined Profile endpoints andenabled_entriesreplacingentries(Terraform v5.17.0, Terraform v5.13.0).cloudflare_zero_trust_tunnel_cloudflared_config: remove warp_routing from cloudflared_config (Terraform v5.13.0).- Workers split resources: imports for
cloudflare_workerandcloudflare_worker_version; note thatcloudflare_workers_script_subdomainmay be redundant withcloudflare_worker(Terraform v5.13.0, Terraform v5.15.0).
Upgrade workflow: order of operations
Section titled “Upgrade workflow: order of operations”-
Pin the target provider version in
required_providersusing a version called out in Cloudflare’s Terraform changelog (for example Terraform v5.20.0 for the latest feature and drift fixes listed there). -
Run
terraform init -upgradein a branch or workspace clone so dependency lock files refresh against the new provider binary. -
Run
terraform planand scan for state upgrader activity, destroy/recreate warnings, and breaking resources (cloudflare_api_token,cloudflare_account_token, deprecated snippets). -
If drift persists on a named resource, find that resource in the versioned posts (v5.17.0 through v5.20.0) before changing HCL—many fixes are patch-level.
-
Apply during a maintenance window after plan is empty or only contains expected token or migration changes.
For zone-level settings managed historically via overrides, follow Cloudflare’s tf-migrate v2 guidance referenced in Terraform v5.19.0. The Configure HTTPS settings tutorial illustrates day-to-day use of cloudflare_zone_setting on v5.
Common mistakes when upgrading or debugging drift
Section titled “Common mistakes when upgrading or debugging drift”- Staying on an old patch while reporting “v5 is broken”—many drift reports match a specific fix in Terraform v5.14.0 or Terraform v5.16.0 for the same resource name.
- Ignoring token breaking changes and applying blindly after Terraform v5.13.0.
- Continuing to use
cloudflare_snippetsafter deprecation (Terraform v5.9). - Managing Workers secrets only outside Terraform while expecting no
workers_scriptdiff—release notes call out drift when a worker has an unmanaged secret (Terraform v5.14.0). - Assuming “stabilized” means zero plan changes—stabilization marks maturity; API churn may still require newer patches.
How to check this on your site
Section titled “How to check this on your site”-
Confirm the provider version in your lock file matches a release you have reviewed in the Terraform product changelog or a specific post such as Terraform v5.19.0.
-
In a safe workspace, run
terraform planand verify whether remaining changes are expected migrations (tokens, snippets rename) versus unexplained drift on resources called out in Terraform v5.5.0 or Terraform v5.8.2. -
For zone settings, cross-check behavior against Configure HTTPS settings using
cloudflare_zone_setting. -
If plan still differs every run, compare your resource types against stabilization and fix lists in Terraform v5.9 and Terraform v5.20.0, then bump to the newest patch that mentions your resource.
-
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.