Skip to content

fix(d1_database): add read_replication default to prevent v5 apply failure - #319

Merged
ssicard merged 1 commit into
mainfrom
fix/d1-database-read-replication
Jul 14, 2026
Merged

fix(d1_database): add read_replication default to prevent v5 apply failure#319
ssicard merged 1 commit into
mainfrom
fix/d1-database-read-replication

Conversation

@ssicard

@ssicard ssicard commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add read_replication = { mode = "disabled" } to every cloudflare_d1_database resource block during v4→v5 migration.

Problem

The E2E CI run (#278) is failing because all cloudflare_d1_database resources get a 400 Bad Request from the D1 API:

"Invalid property: read_replication => Expected object, received null"

Root cause chain:

  1. v4 state has no read_replication field (it did not exist in v4)
  2. tf-migrate runs — the d1_database migrator was a no-op, so no read_replication is added to the config
  3. The v5.22.0 provider's new state upgrader (UpgradeFromLegacyV0) initializes read_replication as nil in state
  4. Terraform sends read_replication: null in the PUT request
  5. The D1 API rejects null — it expects {"mode": "disabled"}, not null

Fix

TransformConfig now sets read_replication = { mode = "disabled" } on every d1_database block that does not already have it. This matches the API default and prevents the null-rejection error.

A corresponding provider-side fix (initializing read_replication to {mode:"disabled"} in the state upgrader) will be submitted separately to terraform-provider-cloudflare.

Changes

  • internal/resources/d1_database/v4_to_v5.go — set read_replication default in TransformConfig
  • internal/resources/d1_database/v4_to_v5_test.go — updated 5 expected outputs + added idempotency test
  • integration/v4_to_v5/testdata/d1_database/expected/d1_database.tf — all 8 resource blocks updated

Testing

go test -v ./internal/resources/d1_database/...   # 6/6 pass
TEST_RESOURCE=d1_database go test -v -run TestSingleResource ./integration/...  # pass

…ilure

The D1 API returns read_replication={mode:"disabled"} as a default on
read but rejects null on update. After migrating from v4 to v5, the
provider state upgrader initializes read_replication as null (since the
field did not exist in v4), causing all d1_database resources to fail
with "400 Bad Request: Invalid property: read_replication => Expected
object, received null" on the next terraform apply.

Add read_replication = { mode = "disabled" } to every d1_database
resource block during migration if not already present. This matches the
API default and prevents the null-rejection error.

A corresponding provider-side fix (initializing read_replication to
{mode:"disabled"} in the state upgrader) will be submitted separately to
terraform-provider-cloudflare.
@ssicard
ssicard requested a review from a team as a code owner July 14, 2026 18:05
@ssicard ssicard self-assigned this Jul 14, 2026
@ssicard
ssicard merged commit 7d3df53 into main Jul 14, 2026
11 checks passed
@ssicard
ssicard deleted the fix/d1-database-read-replication branch July 14, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants