-
Notifications
You must be signed in to change notification settings - Fork 9.9k
docs: add new workers improvements changelog #24025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+133
−0
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
...content/changelog/workers/2025-08-14-workers-terraform-and-sdk-improvements.mdx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| --- | ||
| title: Improvements to the Workers Terraform resources and SDKs | ||
| description: Multiple improvements to the Workers Terraform resources and SDKs including fixes for plan diffs, file uploads, and Python Workers support. | ||
| products: | ||
| - workers | ||
| date: 2025-08-14 | ||
| --- | ||
|
|
||
| The recent [Cloudflare Terraform Provider](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/workers_script) and SDK releases (such as [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript)) bring significant improvements to the Workers developer experience. These updates focus on reliability, performance, and adding Python Workers support. | ||
markjmiller marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Terraform Improvements | ||
|
|
||
| ### Fixed Unwarranted Plan Diffs | ||
|
|
||
| Resolved several issues with the `cloudflare_workers_script` resource that resulted in unwarranted plan diffs, including: | ||
|
|
||
| - Using Durable Objects migrations | ||
| - Using some bindings such as `secret_text` | ||
| - Using smart placement | ||
|
|
||
| A resource should never show a plan diff if there isn't an actual change. This fix reduces unnecessary noise in your Terraform plan and is available in Cloudflare Terraform Provider 5.8.0. | ||
|
|
||
| ### Improved File Management | ||
|
|
||
| You can now specify `content_file` and `content_sha256` instead of `content`. This prevents the Workers script content from being stored in the state file which greatly reduces plan diff size and noise. If your workflow synced plans remotely, this should now happen much faster since there is less data to sync. This is available in Cloudflare Terraform Provider 5.7.0. | ||
|
|
||
| ```tf | ||
| resource "cloudflare_workers_script" "my_worker" { | ||
| account_id = "123456789" | ||
| script_name = "my_worker" | ||
| main_module = "worker.mjs" | ||
| content_file = "worker.mjs" | ||
| content_sha256 = filesha256("worker.mjs") | ||
| } | ||
| ``` | ||
|
|
||
| ### Assets Headers and Redirects Support | ||
|
|
||
| Fixed the `cloudflare_workers_script` resource to properly support headers and redirects for Assets: | ||
|
|
||
| ```tf | ||
| resource "cloudflare_workers_script" "my_worker" { | ||
| account_id = "123456789" | ||
| script_name = "my_worker" | ||
| main_module = "worker.mjs" | ||
| content_file = "worker.mjs" | ||
| content_sha256 = filesha256("worker.mjs") | ||
| assets = { | ||
| config = { | ||
| headers = file("_headers") | ||
| redirects = file("_redirects") | ||
| } | ||
| # Completion jwt from: | ||
| # https://developers.cloudflare.com/api/resources/workers/subresources/assets/subresources/upload/ | ||
| jwt = "jwt" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Available in Cloudflare Terraform Provider 5.8.0. | ||
|
|
||
| ### Python Workers Support | ||
|
|
||
| Added support for uploading [Python Workers](/workers/languages/python/) (beta) in Terraform. You can now deploy Python Workers with: | ||
|
|
||
| ```tf | ||
| resource "cloudflare_workers_script" "my_worker" { | ||
| account_id = "123456789" | ||
| script_name = "my_worker" | ||
| content_file = "worker.py" | ||
| content_sha256 = filesha256("worker.py") | ||
| content_type = "text/x-python" | ||
| } | ||
| ``` | ||
|
|
||
| Available in Cloudflare Terraform Provider 5.8.0. | ||
|
|
||
| ## SDK Enhancements | ||
|
|
||
| ### Improved File Upload API | ||
|
|
||
| Fixed an issue where Workers script versions in the SDK did not allow uploading files. This now works, and also has an improved files upload interface: | ||
|
|
||
| ```js | ||
| const scriptContent = ` | ||
| export default { | ||
| async fetch(request, env, ctx) { | ||
| return new Response('Hello World!', { status: 200 }); | ||
| } | ||
| }; | ||
| `; | ||
|
|
||
| client.workers.scripts.versions.create('my-worker', { | ||
| account_id: '123456789', | ||
| metadata: { | ||
| main_module: 'my-worker.mjs', | ||
| }, | ||
| files: [ | ||
| await toFile( | ||
| Buffer.from(scriptContent), | ||
| 'my-worker.mjs', | ||
| { | ||
| type: "application/javascript+module", | ||
| } | ||
| ) | ||
| ] | ||
| }); | ||
| ``` | ||
|
|
||
| Will be available in cloudflare-typescript 4.6.0. A similar change will be available in cloudflare-python 4.4.0. | ||
|
|
||
| ### Fixed updating KV values | ||
|
|
||
| Previously when creating a KV value like this: | ||
|
|
||
| ```js | ||
| await cf.kv.namespaces.values.update("my-kv-namespace", "key1", { | ||
| account_id: "123456789", | ||
| metadata: "my metadata", | ||
| value: JSON.stringify({ | ||
| hello: "world" | ||
| }) | ||
| }); | ||
| ``` | ||
|
|
||
| ...and recalling it in your Worker like this: | ||
| ```ts | ||
| const value = await c.env.KV.get<{hello: string}>("key1", "json"); | ||
| ``` | ||
|
|
||
| You'd get back this: `{metadata:'my metadata', value:"{'hello':'world'}"}` instead of the correct value of `{hello: 'world'}` | ||
|
|
||
| This is fixed in cloudflare-typescript 4.5.0 and will be fixed in cloudflare-python 4.4.0. | ||
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.
Uh oh!
There was an error while loading. Please reload this page.