Skip to content

fix(worker_version): placement config ignored and causes forced replacements - #7207

Open
gabrielgiordan wants to merge 3 commits into
cloudflare:mainfrom
gabrielgiordan:fix/worker-version-placement-settings
Open

fix(worker_version): placement config ignored and causes forced replacements#7207
gabrielgiordan wants to merge 3 commits into
cloudflare:mainfrom
gabrielgiordan:fix/worker-version-placement-settings

Conversation

@gabrielgiordan

Copy link
Copy Markdown

Fixes #7206

  • I understand that this repository is auto-generated and my pull request may not be merged

Problem

placement was tagged json:"placement,optional" on the model, so it was
serialized into the version upload body — an endpoint that silently ignores it.
On every subsequent refresh, Read() found no placement in the response and
wrote null to state, diverging from config and forcing a replacement on every plan.

Fix

  • Change the json tag to json:"-,optional" so placement is excluded from the version upload body.
  • After version creation, apply placement via PATCH .../scripts/{name}/settings — the correct endpoint for this setting.
  • In Read(), fetch placement back from GET .../scripts/{name}/settings so state stays in sync.
  • Fix ImportState to also call the settings GET, so imported resources don't show drift on the first plan.

Acceptance test run results

  • I have added or updated acceptance tests for my changes
  • I have run acceptance tests for my changes and included the results below

Steps to run acceptance tests

TF_ACC=1 go test ./internal/services/worker_version/... -run TestAccCloudflareWorkerVersion_Placement -v

Test output

…n refresh

The versions endpoint (POST .../versions) does not support placement;
it was being silently ignored. The correct endpoint is
PATCH .../scripts/{name}/settings. This caused two bugs:

1. Placement was never applied — CF dashboard always showed Default.
2. Versions.Get() never returns placement (script-level, not
   version-level), so state always read back null, forcing a
   replacement on every subsequent plan.

Fix: exclude placement from the version upload body (json:"-"),
call ScriptAndVersionSettings.Edit() after each version creation to
set or clear placement, and call ScriptAndVersionSettings.Get() in
Read() to populate placement in state from the source of truth.

Fixes cloudflare#7206
Fix ImportState to fetch placement from settings API, matching Read().
Add table-driven tests for placementFromSettings. Note target field
as not yet implemented in the SDK union type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudflare_worker_version: placement field silently ignored — sent to wrong API endpoint, causes infinite forced replacement

2 participants