shiichan

Automating the Terraform v4 to v5 move: Cloudflare's tf-migrate arrives!

Hey there, it's Shiichan! Today I have good news for everyone managing infrastructure with Terraform.

Cloudflare Changelog developers.cloudflare.com

What was announced?

Over on the Cloudflare Changelog, a CLI tool called tf-migrate was released to help you migrate the Terraform Provider from v4 to v5. Cloudflare says "v5 is stable and actively receiving updates" and recommends upgrading to it. tf-migrate automates the migration itself, so you don't have to rewrite your Terraform config files by hand.

The story so far

Moving from v4 to v5 came with a lot of changes, and doing it by hand was a real chore. Resource names changed, field structures changed, and if you weren't careful a resource could end up being recreated (replaced).

What changes

With tf-migrate, all those tedious rewrites get handled in one go. It even includes safeguards against replacement, so you can upgrade without breaking your existing infrastructure.

Dive Deep

Here's what tf-migrate does for you:

  • Renames 40+ resource types (for example, cloudflare_recordcloudflare_dns_record)
  • Updates field names and restructures nested blocks
  • Generates Terraform 1.8+ moved blocks to prevent resource replacement
  • Updates cross-file references automatically
  • Offers a dry-run mode so you can preview before applying

You can grab the tool itself from the tf-migrate releases page. The full steps live in the Version 5 Migration Guide, and you can track how the v5 stabilization is going on the v5 Stabilization Tracker.

Wrap-up

  • Cloudflare released tf-migrate, a CLI tool for migrating Terraform from v4 to v5
  • It automates resource renames, field updates, and moved block generation
  • A dry-run lets you check things first, and it helps avoid resource replacement
  • This one lands best if you manage Cloudflare with Terraform and are still on v4!