fix(d1_database): add read_replication default to prevent v5 apply failure - #319
Merged
Conversation
…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.
rotem-cloud
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
read_replication = { mode = "disabled" }to everycloudflare_d1_databaseresource block during v4→v5 migration.Problem
The E2E CI run (#278) is failing because all
cloudflare_d1_databaseresources get a400 Bad Requestfrom the D1 API:Root cause chain:
read_replicationfield (it did not exist in v4)read_replicationis added to the configUpgradeFromLegacyV0) initializesread_replicationasnilin stateread_replication: nullin the PUT request{"mode": "disabled"}, not nullFix
TransformConfignow setsread_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_replicationto{mode:"disabled"}in the state upgrader) will be submitted separately toterraform-provider-cloudflare.Changes
internal/resources/d1_database/v4_to_v5.go— setread_replicationdefault inTransformConfiginternal/resources/d1_database/v4_to_v5_test.go— updated 5 expected outputs + added idempotency testintegration/v4_to_v5/testdata/d1_database/expected/d1_database.tf— all 8 resource blocks updatedTesting