fix(worker_version): placement config ignored and causes forced replacements - #7207
Open
gabrielgiordan wants to merge 3 commits into
Open
fix(worker_version): placement config ignored and causes forced replacements#7207gabrielgiordan wants to merge 3 commits into
gabrielgiordan wants to merge 3 commits into
Conversation
…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.
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.
Fixes #7206
Problem
placementwas taggedjson:"placement,optional"on the model, so it wasserialized into the version upload body — an endpoint that silently ignores it.
On every subsequent refresh,
Read()found no placement in the response andwrote
nullto state, diverging from config and forcing a replacement on every plan.Fix
json:"-,optional"so placement is excluded from the version upload body.PATCH .../scripts/{name}/settings— the correct endpoint for this setting.Read(), fetch placement back fromGET .../scripts/{name}/settingsso state stays in sync.ImportStateto also call the settings GET, so imported resources don't show drift on the first plan.Acceptance test run results
Steps to run acceptance tests
TF_ACC=1 go test ./internal/services/worker_version/... -run TestAccCloudflareWorkerVersion_Placement -v
Test output