Skip to content

Commit f033f14

Browse files
markjmillerkorinne
andauthored
docs: add 2025-06-17 fixes to workers changelog (#23086)
* docs: add 2025-06-17 fixes to workers changelog * updates to changelog to focus on before and after * small tweaks to example * Update src/content/changelog/workers/2025-06-17-workers-terraform-sdk-api-fixes.mdx --------- Co-authored-by: korinne <[email protected]> Co-authored-by: korinne <[email protected]>
1 parent eb7cae3 commit f033f14

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
title: Automate Worker deployments with a simplified SDK and more reliable Terraform provider
3+
description: Various fixes and improvements have been made to Workers Terraform resources, SDKs, APIs, and API docs.
4+
products:
5+
- d1
6+
- workers
7+
- workers-for-platforms
8+
date: 2025-06-19T14:00:00Z
9+
---
10+
11+
import { TypeScriptExample } from "~/components";
12+
13+
## Simplified Worker Deployments with our SDKs
14+
15+
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.
16+
17+
This new interface is available in:
18+
19+
- [cloudflare-typescript](https://github.com/cloudflare/cloudflare-typescript) (4.4.1)
20+
- [cloudflare-python](https://github.com/cloudflare/cloudflare-python) (4.3.1)
21+
22+
For complete examples, see our guide on [programmatic Worker deployments](/workers/platform/infrastructure-as-code).
23+
24+
### The Old way: Manual API calls
25+
26+
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.
27+
28+
For example, here's how you would upload a Worker script previously with cURL:
29+
30+
```bash
31+
curl https://api.cloudflare.com/client/v4/accounts/<account_id>/workers/scripts/my-hello-world-script \
32+
-X PUT \
33+
-H 'Authorization: Bearer <api_token>' \
34+
-F 'metadata={
35+
"main_module": "my-hello-world-script.mjs",
36+
"bindings": [
37+
{
38+
"type": "plain_text",
39+
"name": "MESSAGE",
40+
"text": "Hello World!"
41+
}
42+
],
43+
"compatibility_date": "$today"
44+
};type=application/json' \
45+
-F 'my-hello-world-script.mjs=@-;filename=my-hello-world-script.mjs;type=application/javascript+module' <<EOF
46+
export default {
47+
async fetch(request, env, ctx) {
48+
return new Response(env.MESSAGE, { status: 200 });
49+
}
50+
};
51+
EOF
52+
```
53+
54+
### After: SDK interface
55+
56+
With the new SDK interface, you can now define your entire Worker configuration using a single, structured object.
57+
58+
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.
59+
60+
Here's how you can now programmatically deploy a Worker via the [`cloudflare-typescript` SDK](https://github.com/cloudflare/cloudflare-typescript)
61+
62+
<TypeScriptExample>
63+
```ts
64+
import Cloudflare from 'cloudflare';
65+
import { toFile } from 'cloudflare/index';
66+
67+
// ... client setup, script content, etc.
68+
69+
const script = await client.workers.scripts.update(scriptName, {
70+
account_id: accountID,
71+
metadata: {
72+
main_module: scriptFileName,
73+
bindings: [],
74+
},
75+
files: {
76+
[scriptFileName]: await toFile(Buffer.from(scriptContent), scriptFileName, {
77+
type: 'application/javascript+module',
78+
}),
79+
},
80+
});
81+
```
82+
83+
</TypeScriptExample>
84+
85+
View the complete example here: https://github.com/cloudflare/cloudflare-typescript/blob/main/examples/workers/script-upload.ts
86+
87+
## Terraform provider improvements
88+
89+
We've also made several fixes and enhancements to the [Cloudflare Terraform provider](https://github.com/cloudflare/terraform-provider-cloudflare):
90+
91+
- 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.
92+
- 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.
93+
- 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.
94+
- 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.
95+
96+
## API improvements
97+
98+
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.
99+
100+

0 commit comments

Comments
 (0)