-
Notifications
You must be signed in to change notification settings - Fork 8.8k
docs: add 2025-06-17 fixes to workers changelog #23086
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8d910e3
docs: add 2025-06-17 fixes to workers changelog
markjmiller acecef7
updates to changelog to focus on before and after
korinne a80e88f
small tweaks to example
korinne 8993f0c
Update src/content/changelog/workers/2025-06-17-workers-terraform-sdk…
korinne 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
100 changes: 100 additions & 0 deletions
100
src/content/changelog/workers/2025-06-17-workers-terraform-sdk-api-fixes.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,100 @@ | ||
--- | ||
title: Automate Worker deployments with a simplified SDK and more reliable Terraform provider | ||
description: Various fixes and improvements have been made to Workers Terraform resources, SDKs, APIs, and API docs. | ||
products: | ||
- d1 | ||
- workers | ||
- workers-for-platforms | ||
date: 2025-06-19T14:00:00Z | ||
--- | ||
|
||
import { TypeScriptExample } from "~/components"; | ||
|
||
## Simplified Worker Deployments with our SDKs | ||
|
||
We've simplified the programmatic deployment of Workers via our [Cloudflare SDKs](/fundamentals/api/reference/sdks/). This update abstracts away the low-level complexities of the `multipart/form-data` upload process, allowing you to focus on your code while we handle the deployment mechanics. | ||
|
||
This new interface is available in: | ||
|
||
- [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) (4.4.1) | ||
- [cloudflare-python](https://github.com/cloudflare/cloudflare-python) (4.3.1) | ||
|
||
For complete examples, see our guide on [programmatic Worker deployments](/workers/platform/infrastructure-as-code). | ||
|
||
### The Old way: Manual API calls | ||
|
||
Previously, deploying a Worker programmatically required manually constructing a `multipart/form-data` HTTP request, packaging your code and a separate `metadata.json` file. This was more complicated and verbose, and prone to formatting errors. | ||
|
||
For example, here's how you would upload a Worker script previously with cURL: | ||
|
||
```bash | ||
curl https://api.cloudflare.com/client/v4/accounts/<account_id>/workers/scripts/my-hello-world-script \ | ||
-X PUT \ | ||
-H 'Authorization: Bearer <api_token>' \ | ||
-F 'metadata={ | ||
"main_module": "my-hello-world-script.mjs", | ||
"bindings": [ | ||
{ | ||
"type": "plain_text", | ||
"name": "MESSAGE", | ||
"text": "Hello World!" | ||
} | ||
], | ||
"compatibility_date": "$today" | ||
};type=application/json' \ | ||
-F 'my-hello-world-script.mjs=@-;filename=my-hello-world-script.mjs;type=application/javascript+module' <<EOF | ||
export default { | ||
async fetch(request, env, ctx) { | ||
return new Response(env.MESSAGE, { status: 200 }); | ||
} | ||
}; | ||
EOF | ||
``` | ||
|
||
### After: SDK interface | ||
|
||
With the new SDK interface, you can now define your entire Worker configuration using a single, structured object. | ||
|
||
This approach allows you to specify metadata like `main_module`, `bindings`, and `compatibility_date` as clearer properties directly alongside your script content. Our SDK takes this logical object and automatically constructs the complex multipart/form-data API request behind the scenes. | ||
|
||
Here's how you can now programmatically deploy a Worker via the [`cloudflare-typescript` SDK](https://github.com/cloudflare/cloudflare-typescript) | ||
|
||
<TypeScriptExample> | ||
```ts | ||
import Cloudflare from 'cloudflare'; | ||
import { toFile } from 'cloudflare/index'; | ||
|
||
// ... client setup, script content, etc. | ||
|
||
const script = await client.workers.scripts.update(scriptName, { | ||
account_id: accountID, | ||
metadata: { | ||
main_module: scriptFileName, | ||
bindings: [], | ||
}, | ||
files: { | ||
[scriptFileName]: await toFile(Buffer.from(scriptContent), scriptFileName, { | ||
type: 'application/javascript+module', | ||
}), | ||
}, | ||
}); | ||
``` | ||
|
||
</TypeScriptExample> | ||
|
||
View the complete example here: https://github.com/cloudflare/cloudflare-typescript/blob/main/examples/workers/script-upload.ts | ||
|
||
## Terraform provider improvements | ||
|
||
We've also made several fixes and enhancements to the [Cloudflare Terraform provider](https://github.com/cloudflare/terraform-provider-cloudflare): | ||
|
||
- Fixed the [`cloudflare_workers_script`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/workers_script) resource in Terraform, which previously was producing a diff even when there were no changes. Now, your `terraform plan` outputs will be cleaner and more reliable. | ||
- Fixed the [`cloudflare_workers_for_platforms_dispatch_namespace`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/workers_for_platforms_dispatch_namespace), where the provider would attempt to recreate the namespace on a `terraform apply`. The resource now correctly reads its remote state, ensuring stability for production environments and CI/CD workflows. | ||
- The [`cloudflare_workers_route`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/workers_route) resource now allows for the `script` property to be empty, null, or omitted to indicate that pattern should be negated for all scripts (see routes [docs](/workers/configuration/routing/routes)). You can now reserve a pattern or temporarily disable a Worker on a route without deleting the route definition itself. | ||
- Using `primary_location_hint` in the [`cloudflare_d1_database`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/d1_database) resource will no longer always try to recreate. You can now safely change the location hint for a D1 database without causing a destructive operation. | ||
|
||
## API improvements | ||
|
||
We've also properly documented the [Workers Script And Version Settings](/api/resources/workers/subresources/scripts/subresources/script_and_version_settings) in our public OpenAPI spec and SDKs. | ||
|
||
|
Oops, something went wrong.
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.