You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/configuration/secrets.mdx
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,12 @@ import { Render,DashButton } from "~/components";
11
11
12
12
Secrets are a type of binding that allow you to attach encrypted text values to your Worker. Secrets are used for storing sensitive information like API keys and auth tokens. Secrets are programmatically available on the [`env` parameter](/workers/runtime-apis/handlers/fetch/#parameters) passed to your Worker's [`fetch` event handler](/workers/runtime-apis/handlers/fetch/), and may also be accessible via [`process.env`](/workers/configuration/environment-variables) in Workers that support Node.js compatibility.
13
13
14
+
:::note[Secrets are bindings, not separate resources]
15
+
16
+
Secrets are not managed as standalone resources. Instead, they are implemented as bindings attached to your Worker or Worker version. When using tools like Wrangler, the CLI handles this binding automatically. When using Infrastructure as Code tools like [Terraform](/workers/platform/infrastructure-as-code/) or the [Cloudflare API](/api/resources/workers/) directly, secrets must be explicitly included as `secret_text` bindings on your `cloudflare_workers_script` or `cloudflare_worker_version` resources.
17
+
18
+
:::
19
+
14
20
## Access your secrets with Workers
15
21
16
22
Secrets can be accessed from Workers as you would any other [environment variables](/workers/configuration/environment-variables/). For instance, given a `DB_CONNECTION_STRING` secret, you can access it in your Worker code:
To make this succeed, you first have to comment out the `durable_object` binding block, apply the plan, uncomment it, comment out the `migrations` block, then apply again. This time the plan will succeed. This also applies to the API or SDKs. This is an example where it makes sense to just manage the `cloudflare_worker` and/or `cloudflare_workers_deployment` resources while using Wrangler for build and Version management.
420
+
421
+
## Considerations with Secrets
422
+
423
+
[Secrets](/workers/configuration/secrets/) are not managed as standalone resources in Terraform or the API. Instead, they must be included as bindings on your Worker script or version.
424
+
425
+
### Secret Text Binding
426
+
427
+
When using Terraform or the API, use a `secret_text` binding to attach encrypted secrets to your Worker:
The secret will be encrypted and accessible in your Worker via `env.API_KEY`.
497
+
498
+
### Secrets Store
499
+
500
+
For centralized secrets management across multiple Workers, [Secrets Store](/secrets-store/) (beta) provides account-level secrets. While Secrets Store can currently be accessed from Workers using `secrets_store_secret` bindings, a dedicated Terraform resource for managing Secrets Store is planned for GA, tentatively targeting Q1 2026.
501
+
502
+
In the meantime, you can reference an existing Secrets Store managed outside of Terraform:
0 commit comments