Skip to content

feat: add cloudflare_worker_secret migration support - #320

Merged
ssicard merged 3 commits into
mainfrom
feat/workers-secret-migration
Aug 5, 2026
Merged

feat: add cloudflare_worker_secret migration support#320
ssicard merged 3 commits into
mainfrom
feat/workers-secret-migration

Conversation

@ssicard

@ssicard ssicard commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds v4-to-v5 migration for cloudflare_workers_secret and the deprecated cloudflare_worker_secret resources. In v5, standalone worker secrets no longer exist -- they are managed as secret_text bindings on the cloudflare_workers_script resource.

Migration behavior

  • Handles both cloudflare_workers_secret (plural) and cloudflare_worker_secret (singular/deprecated
  • Cross-resource merge: secrets are automatically folded into their parent workers_script bindings list when both are in the same file)
    Output of migrations hows a warning, since a deletion occurs:
⚠ Resource removed: cloudflare_workers_secret.literal_match_secret

The cloudflare_workers_secret resource has been removed in v5. Secrets are now managed as
bindings on the cloudflare_workers_script resource (script_name = "cftftest-literal-match").

If the parent cloudflare_workers_script is in the same file, the secret has
been automatically merged into its bindings list. Otherwise, add the
following binding to the parent resource manually:

  {
    type = "secret_text"
    name = "LITERAL_SECRET"
    text = "literal-secret-value"
  }

A 'removed' block has been generated to clean up the state entry during the next apply.

Note: In v4, secrets were managed via a separate API and could be updated
without redeploying the Worker script. In v5, secret_text bindings are part
of the script resource, so future secret changes will trigger a script
redeployment.

E2E Test Results

========================================
✓ E2E Test Complete!
========================================

Summary:

  Step 1: v4 terraform apply
    Status: ✓ SUCCESS

  Step 2: Migration (v4 → v5)
    Status: ✓ SUCCESS

  Step 3: v5 plan (before apply)
    Status: ✓ SUCCESS - Drift matched exemptions
    Result: 26 material changes (26 matched exemptions, 0 unmatched)
    Terraform: Plan: 0 to add, 5 to change, 0 to destroy.

  Step 4: v5 terraform apply
    Status: ✓ SUCCESS

  Step 5: v5 plan (after apply)
    Status: ✓ SUCCESS - Stable state achieved
    Result: No changes detected

Adds v4-to-v5 migration for cloudflare_workers_secret and the deprecated
cloudflare_worker_secret resources. In v5, standalone worker secrets no
longer exist; they are managed as secret_text bindings on the
cloudflare_workers_script resource.

Migration behavior:
- Cross-resource merge: secrets are automatically folded into their parent
  workers_script bindings list when both are in the same file
- Existing bindings preserved via concat()
- Parent matching by resource reference or literal script_name
- Orphan secrets (parent not in file) get removed block + diagnostic
- PhaseOneTransformer implemented for two-phase migration (required because
  the v5 provider has no schema for workers_secret)

Handles both cloudflare_workers_secret (plural) and cloudflare_worker_secret
(singular/deprecated) identically.

Ref: APIX-1259
@ssicard ssicard self-assigned this Jul 15, 2026
ssicard added 2 commits July 15, 2026 15:26
The v5 provider has no schema for cloudflare_workers_secret or
cloudflare_worker_secret. The E2E runner must remove these state entries
before running terraform init/plan with the v5 provider, matching the
existing pattern for zone_settings_override and split_tunnel.
…overage

- Add drift exemptions targeting cloudflare_workers_script (not
  cloudflare_workers_secret) since secrets are folded into script bindings
- Suppress resource_type mismatch warning when resource_name_patterns
  provides intentional cross-resource scoping
- Fix diagnostic: replace incorrect 'terraform state rm' instruction with
  note about removed block handling state cleanup
- Add redeployment behavior note to diagnostic warning
- Harden concat() append with suffix validation
- Add idempotency test for ProcessCrossResourceConfigMigration
- Add diagnostic content test
- Fix import ordering in registry.go
- Remove README.md (docs belong in provider migration guides)
@ssicard
ssicard marked this pull request as ready for review July 16, 2026 21:53
@ssicard
ssicard requested a review from a team as a code owner July 16, 2026 21:53
@ssicard
ssicard merged commit 8c84b67 into main Aug 5, 2026
11 checks passed
@ssicard
ssicard deleted the feat/workers-secret-migration branch August 5, 2026 20:45
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.

3 participants