Skip to content
Start here

Scripts

resource cloudflare_workers_script

required Expand Collapse
script_name: String

Name of the script, used in URLs and route configuration.

account_id: String

Identifier.

metadata: Attributes

JSON-encoded metadata about the uploaded parts and Worker configuration.

annotations?: Attributes

Annotations for the version created by this upload.

workers_message?: String

Human-readable message about the version.

workers_tag?: String

User-provided identifier for the version.

assets?: Attributes

Configuration for assets within a Worker.

config?: Attributes

Configuration for assets within a Worker.

headers?: String

The contents of a _headers file (used to attach custom headers on asset responses).

redirects?: String

The contents of a _redirects file (used to apply redirects or proxy paths ahead of asset serving).

html_handling?: String

Determines the redirects and rewrites of requests for HTML content.

not_found_handling?: String

Determines the response when a request does not match a static asset, and there is no Worker script.

run_worker_first?: List[String]

Contains a list path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.

Deprecatedserve_directly?: Bool

When true and the incoming request matches an asset, that will be served instead of invoking the Worker script. When false, requests will always invoke the Worker script.

jwt?: String

Token provided upon successful upload of all files from a registered manifest.

bindings?: List[Attributes]

List of bindings attached to a Worker. You can find more about bindings on our docs: https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/#bindings.

name: String

A JavaScript variable name for the binding.

type: String

The kind of resource that the binding provides.

instance_name?: String

The user-chosen instance name. Must exist at deploy time. The worker can search, chat, update, and manage items/jobs on this instance.

namespace?: String

The namespace the instance belongs to. Defaults to "default" if omitted. Customers who don't use namespaces can simply omit this field.

dataset?: String

The name of the dataset to bind to.

id?: String

Identifier of the D1 database to bind to.

part?: String

The name of the file containing the data content. Only accepted for service worker syntax Workers.

outbound?: Attributes

Outbound worker.

params?: List[Attributes]

Pass information from the Dispatch Worker to the Outbound Worker through the parameters.

name: String

Name of the parameter.

worker?: Attributes

Outbound worker.

entrypoint?: String

Entrypoint to invoke on the outbound worker.

environment?: String

Environment of the outbound worker.

service?: String

Name of the outbound worker.

class_name?: String

The exported class name of the Durable Object.

dispatch_namespace?: String

The dispatch namespace the Durable Object script belongs to.

environment?: String

The environment of the script_name to bind to.

namespace_id?: String

Namespace identifier tag.

script_name?: String

The script where the Durable Object is defined, if it is external to this Worker.

old_name?: String

The old name of the inherited binding. If set, the binding will be renamed from old_name to name in the new version. If not set, the binding will keep the same name between versions.

version_id?: String

Identifier for the version to inherit the binding from, which can be the version ID or the literal "latest" to inherit from the latest version. Defaults to inheriting the binding from the latest version.

json?: JSON

JSON data to use.

certificate_id?: String

Identifier of the certificate to bind to.

text?: String

The text value to use.

pipeline?: String

Name of the Pipeline to bind to.

queue_name?: String

Name of the Queue to bind to.

simple?: Attributes

The rate limit configuration.

limit: Float64

The limit (requests per period).

period: Int64

The period in seconds.

bucket_name?: String

R2 bucket to bind to.

jurisdiction?: String

The jurisdiction of the R2 bucket.

allowed_destination_addresses?: List[String]

List of allowed destination addresses.

allowed_sender_addresses?: List[String]

List of allowed sender addresses.

destination_address?: String

Destination address for the email.

service?: String

Name of Worker to bind to.

entrypoint?: String

Entrypoint to invoke on the target Worker.

index_name?: String

Name of the Vectorize index to bind to.

secret_name?: String

Name of the secret in the store.

store_id?: String

ID of the store containing the secret.

algorithm?: JSON

Algorithm-specific key parameters. Learn more.

format?: String

Data format of the key. Learn more.

usages?: Set[String]

Allowed operations with the key. Learn more.

key_base64?: String

Base64-encoded key data. Required if format is "raw", "pkcs8", or "spki".

key_jwk?: JSON

Key data in JSON Web Key format. Required if format is "jwk".

workflow_name?: String

Name of the Workflow to bind to.

service_id?: String

Identifier of the VPC service to bind to.

network_id?: String

Identifier of the network to bind to. Only "cf1:network" is currently supported. Mutually exclusive with tunnel_id.

tunnel_id?: String

UUID of the Cloudflare Tunnel to bind to. Mutually exclusive with network_id.

body_part?: String

Name of the uploaded file that contains the script (e.g. the file adding a listener to the fetch event). Indicates a service worker syntax Worker.

compatibility_date?: String

Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.

compatibility_flags?: Set[String]

Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.

keep_assets?: Bool

Retain assets which exist for a previously uploaded Worker version; used in lieu of providing a completion token.

keep_bindings?: Set[String]

List of binding types to keep from previous_upload.

limits?: Attributes

Limits to apply for this Worker.

cpu_ms?: Int64

The amount of CPU time this Worker can use in milliseconds.

logpush?: Bool

Whether Logpush is turned on for the Worker.

main_module?: String

Name of the uploaded file that contains the main module (e.g. the file exporting a fetch handler). Indicates a module syntax Worker.

migrations?: Attributes

Migrations to apply for Durable Objects associated with this Worker.

deleted_classes?: List[String]

A list of classes to delete Durable Object namespaces from.

new_classes?: List[String]

A list of classes to create Durable Object namespaces from.

new_sqlite_classes?: List[String]

A list of classes to create Durable Object namespaces with SQLite from.

new_tag?: String

Tag to set as the latest migration tag.

old_tag?: String

Tag used to verify against the latest migration tag for this Worker. If they don't match, the upload is rejected.

renamed_classes?: List[Attributes]

A list of classes with Durable Object namespaces that were renamed.

from?: String
to?: String
transferred_classes?: List[Attributes]

A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.

from?: String
from_script?: String
to?: String
steps?: List[Attributes]

Migrations to apply in order.

deleted_classes?: List[String]

A list of classes to delete Durable Object namespaces from.

new_classes?: List[String]

A list of classes to create Durable Object namespaces from.

new_sqlite_classes?: List[String]

A list of classes to create Durable Object namespaces with SQLite from.

renamed_classes?: List[Attributes]

A list of classes with Durable Object namespaces that were renamed.

from?: String
to?: String
transferred_classes?: List[Attributes]

A list of transfers for Durable Object namespaces from a different Worker and class to a class defined in this Worker.

from?: String
from_script?: String
to?: String
observability?: Attributes

Observability settings for the Worker.

enabled: Bool

Whether observability is enabled for the Worker.

head_sampling_rate?: Float64

The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

logs?: Attributes

Log settings for the Worker.

enabled: Bool

Whether logs are enabled for the Worker.

invocation_logs: Bool

Whether invocation logs are enabled for the Worker.

destinations?: List[String]

A list of destinations where logs will be exported to.

head_sampling_rate?: Float64

The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist?: Bool

Whether log persistence is enabled for the Worker.

traces?: Attributes

Trace settings for the Worker.

destinations?: List[String]

A list of destinations where traces will be exported to.

enabled?: Bool

Whether traces are enabled for the Worker.

head_sampling_rate?: Float64

The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist?: Bool

Whether trace persistence is enabled for the Worker.

placement?: Attributes

Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.

mode?: String

Enables Smart Placement.

last_analyzed_at: Time

The last time the script was analyzed for Smart Placement.

status: String

Status of Smart Placement.

region?: String

Cloud region for targeted placement in format 'provider:region'.

hostname?: String

HTTP hostname for targeted placement.

host?: String

TCP host and port for targeted placement.

target?: List[Attributes]

Array of placement targets (currently limited to single target).

region?: String

Cloud region in format 'provider:region'.

hostname?: String

HTTP hostname for targeted placement.

host?: String

TCP host:port for targeted placement.

tags?: Set[String]

List of strings to use as tags for this Worker.

tail_consumers?: Set[Attributes]

List of Workers that will consume logs from the attached Worker.

service: String

Name of Worker that is to be the consumer.

environment?: String

Optional environment if the Worker utilizes one.

namespace?: String

Optional dispatch namespace the script belongs to.

usage_model?: String

Usage model for the Worker invocations.

optional Expand Collapse
files?: Set[String]

An array of modules (often JavaScript files) comprising a Worker script. At least one module must be present and referenced in the metadata as main_module or body_part by filename.
Possible Content-Type(s) are: application/javascript+module, text/javascript+module, application/javascript, text/javascript, text/x-python, text/x-python-requirement, application/wasm, text/plain, application/octet-stream, application/source-map.

computed Expand Collapse
id: String

Name of the script, used in URLs and route configuration.

compatibility_date: String

Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.

created_on: Time

When the script was created.

entry_point: String

The entry point for the script.

etag: String

Hashed script content, can be used in a If-None-Match header when updating.

has_assets: Bool

Whether a Worker contains assets.

has_modules: Bool

Whether a Worker contains modules.

last_deployed_from: String

The client most recently used to deploy this Worker.

logpush: Bool

Whether Logpush is turned on for the Worker.

migration_tag: String

The tag of the Durable Object migration that was most recently applied for this Worker.

modified_on: Time

When the script was last modified.

Deprecatedplacement_mode: String
Deprecatedplacement_status: String
startup_time_ms: Int64
tag: String

The immutable ID of the script.

usage_model: String

Usage model for the Worker invocations.

compatibility_flags: Set[String]

Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.

handlers: List[String]

The names of handlers exported as part of the default export.

tags: Set[String]

Tags associated with the Worker.

named_handlers: List[Attributes]

Named exports, such as Durable Object class implementations and named entrypoints.

handlers: List[String]

The names of handlers exported as part of the named export.

name: String

The name of the export.

observability: Attributes

Observability settings for the Worker.

enabled: Bool

Whether observability is enabled for the Worker.

head_sampling_rate: Float64

The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

logs: Attributes

Log settings for the Worker.

enabled: Bool

Whether logs are enabled for the Worker.

invocation_logs: Bool

Whether invocation logs are enabled for the Worker.

destinations: List[String]

A list of destinations where logs will be exported to.

head_sampling_rate: Float64

The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist: Bool

Whether log persistence is enabled for the Worker.

traces: Attributes

Trace settings for the Worker.

destinations: List[String]

A list of destinations where traces will be exported to.

enabled: Bool

Whether traces are enabled for the Worker.

head_sampling_rate: Float64

The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist: Bool

Whether trace persistence is enabled for the Worker.

placement: Attributes

Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.

mode: String

Enables Smart Placement.

last_analyzed_at: Time

The last time the script was analyzed for Smart Placement.

status: String

Status of Smart Placement.

region: String

Cloud region for targeted placement in format 'provider:region'.

hostname: String

HTTP hostname for targeted placement.

host: String

TCP host and port for targeted placement.

target: List[Attributes]

Array of placement targets (currently limited to single target).

region: String

Cloud region in format 'provider:region'.

hostname: String

HTTP hostname for targeted placement.

host: String

TCP host:port for targeted placement.

tail_consumers: Set[Attributes]

List of Workers that will consume logs from the attached Worker.

service: String

Name of Worker that is to be the consumer.

environment: String

Optional environment if the Worker utilizes one.

namespace: String

Optional dispatch namespace the script belongs to.

cloudflare_workers_script

resource "cloudflare_workers_script" "example_workers_script" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
  metadata = {
    annotations = {
      workers_message = "Fixed bug."
      workers_tag = "v1.0.1"
    }
    assets = {
      config = {
        headers = <<EOT
        /dashboard/*
        X-Frame-Options: DENY

        /static/*
        Access-Control-Allow-Origin: *
        EOT
        redirects = <<EOT
        /foo /bar 301
        /news/* /blog/:splat
        EOT
        html_handling = "auto-trailing-slash"
        not_found_handling = "404-page"
        run_worker_first = ["string"]
        serve_directly = true
      }
      jwt = "jwt"
    }
    bindings = [{
      name = "MY_ENV_VAR"
      text = "my_data"
      type = "plain_text"
    }]
    body_part = "worker.js"
    compatibility_date = "2021-01-01"
    compatibility_flags = ["nodejs_compat"]
    keep_assets = false
    keep_bindings = ["string"]
    limits = {
      cpu_ms = 50
    }
    logpush = false
    main_module = "worker.js"
    migrations = {
      deleted_classes = ["string"]
      new_classes = ["string"]
      new_sqlite_classes = ["string"]
      new_tag = "v2"
      old_tag = "v1"
      renamed_classes = [{
        from = "from"
        to = "to"
      }]
      transferred_classes = [{
        from = "from"
        from_script = "from_script"
        to = "to"
      }]
    }
    observability = {
      enabled = true
      head_sampling_rate = 0.1
      logs = {
        enabled = true
        invocation_logs = true
        destinations = ["cloudflare"]
        head_sampling_rate = 0.1
        persist = true
      }
      traces = {
        destinations = ["cloudflare"]
        enabled = true
        head_sampling_rate = 0.1
        persist = true
      }
    }
    placement = {
      mode = "smart"
    }
    tags = ["string"]
    tail_consumers = [{
      service = "my-log-consumer"
      environment = "production"
      namespace = "my-namespace"
    }]
    usage_model = "standard"
  }
  files = ["Example data"]
}

data cloudflare_workers_script

required Expand Collapse
account_id: String

Identifier.

optional Expand Collapse
script_name?: String

Name of the script, used in URLs and route configuration.

filter?: Attributes
tags?: String

Filter scripts by tags. Format: comma-separated list of tag:allowed pairs where allowed is 'yes' or 'no'.

computed Expand Collapse
id: String

Name of the script, used in URLs and route configuration.

script: String

cloudflare_workers_script

data "cloudflare_workers_script" "example_workers_script" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
}

data cloudflare_workers_scripts

required Expand Collapse
account_id: String

Identifier.

optional Expand Collapse
tags?: String

Filter scripts by tags. Format: comma-separated list of tag:allowed pairs where allowed is 'yes' or 'no'.

max_items?: Int64

Max items to fetch, default: 1000

computed Expand Collapse
result: List[Attributes]

The items returned by the data source

id: String

The name used to identify the script.

compatibility_date: String

Date indicating targeted support in the Workers runtime. Backwards incompatible fixes to the runtime following this date will not affect this Worker.

compatibility_flags: Set[String]

Flags that enable or disable certain features in the Workers runtime. Used to enable upcoming features or opt in or out of specific changes not included in a compatibility_date.

created_on: Time

When the script was created.

etag: String

Hashed script content, can be used in a If-None-Match header when updating.

handlers: List[String]

The names of handlers exported as part of the default export.

has_assets: Bool

Whether a Worker contains assets.

has_modules: Bool

Whether a Worker contains modules.

last_deployed_from: String

The client most recently used to deploy this Worker.

logpush: Bool

Whether Logpush is turned on for the Worker.

migration_tag: String

The tag of the Durable Object migration that was most recently applied for this Worker.

modified_on: Time

When the script was last modified.

named_handlers: List[Attributes]

Named exports, such as Durable Object class implementations and named entrypoints.

handlers: List[String]

The names of handlers exported as part of the named export.

name: String

The name of the export.

observability: Attributes

Observability settings for the Worker.

enabled: Bool

Whether observability is enabled for the Worker.

head_sampling_rate: Float64

The sampling rate for incoming requests. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

logs: Attributes

Log settings for the Worker.

enabled: Bool

Whether logs are enabled for the Worker.

invocation_logs: Bool

Whether invocation logs are enabled for the Worker.

destinations: List[String]

A list of destinations where logs will be exported to.

head_sampling_rate: Float64

The sampling rate for logs. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist: Bool

Whether log persistence is enabled for the Worker.

traces: Attributes

Trace settings for the Worker.

destinations: List[String]

A list of destinations where traces will be exported to.

enabled: Bool

Whether traces are enabled for the Worker.

head_sampling_rate: Float64

The sampling rate for traces. From 0 to 1 (1 = 100%, 0.1 = 10%). Default is 1.

persist: Bool

Whether trace persistence is enabled for the Worker.

placement: Attributes

Configuration for Smart Placement. Specify mode='smart' for Smart Placement, or one of region/hostname/host.

mode: String

Enables Smart Placement.

last_analyzed_at: Time

The last time the script was analyzed for Smart Placement.

status: String

Status of Smart Placement.

region: String

Cloud region for targeted placement in format 'provider:region'.

hostname: String

HTTP hostname for targeted placement.

host: String

TCP host and port for targeted placement.

target: List[Attributes]

Array of placement targets (currently limited to single target).

region: String

Cloud region in format 'provider:region'.

hostname: String

HTTP hostname for targeted placement.

host: String

TCP host:port for targeted placement.

Deprecatedplacement_mode: String
Deprecatedplacement_status: String
routes: List[Attributes]

Routes associated with the Worker.

id: String

Identifier.

pattern: String

Pattern to match incoming requests against. Learn more.

script: String

Name of the script to run if the route matches.

tag: String

The immutable ID of the script.

tags: Set[String]

Tags associated with the Worker.

tail_consumers: Set[Attributes]

List of Workers that will consume logs from the attached Worker.

service: String

Name of Worker that is to be the consumer.

environment: String

Optional environment if the Worker utilizes one.

namespace: String

Optional dispatch namespace the script belongs to.

usage_model: String

Usage model for the Worker invocations.

cloudflare_workers_scripts

data "cloudflare_workers_scripts" "example_workers_scripts" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  tags = "production:yes,staging:no"
}

ScriptsSubdomain

resource cloudflare_workers_script_subdomain

required Expand Collapse
account_id: String

Identifier.

script_name: String

Name of the script, used in URLs and route configuration.

enabled: Bool

Whether the Worker should be available on the workers.dev subdomain.

optional Expand Collapse
previews_enabled?: Bool

Whether the Worker's Preview URLs should be available on the workers.dev subdomain.

cloudflare_workers_script_subdomain

resource "cloudflare_workers_script_subdomain" "example_workers_script_subdomain" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
  enabled = true
  previews_enabled = false
}

data cloudflare_workers_script_subdomain

required Expand Collapse
account_id: String

Identifier.

script_name: String

Name of the script, used in URLs and route configuration.

computed Expand Collapse
enabled: Bool

Whether the Worker is available on the workers.dev subdomain.

previews_enabled: Bool

Whether the Worker's Preview URLs are available on the workers.dev subdomain.

cloudflare_workers_script_subdomain

data "cloudflare_workers_script_subdomain" "example_workers_script_subdomain" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
}

ScriptsSchedules

resource cloudflare_workers_cron_trigger

required Expand Collapse
script_name: String

Name of the script, used in URLs and route configuration.

account_id: String

Identifier.

body: List[Attributes]
cron: String
created_on: String
modified_on: String
computed Expand Collapse
id: String

Name of the script, used in URLs and route configuration.

schedules: List[Attributes]
cron: String
created_on: String
modified_on: String

cloudflare_workers_cron_trigger

resource "cloudflare_workers_cron_trigger" "example_workers_cron_trigger" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
  body = [{
    cron = "*/30 * * * *"
  }]
}

data cloudflare_workers_cron_trigger

required Expand Collapse
script_name: String

Name of the script, used in URLs and route configuration.

account_id: String

Identifier.

computed Expand Collapse
id: String

Name of the script, used in URLs and route configuration.

schedules: List[Attributes]
cron: String
created_on: String
modified_on: String

cloudflare_workers_cron_trigger

data "cloudflare_workers_cron_trigger" "example_workers_cron_trigger" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
}

ScriptsDeployments

resource cloudflare_workers_deployment

required Expand Collapse
account_id: String

Identifier.

script_name: String

Name of the script, used in URLs and route configuration.

strategy: String
versions: List[Attributes]
percentage: Float64
version_id: String
optional Expand Collapse
annotations?: Attributes
workers_message?: String

Human-readable message about the deployment. Truncated to 100 bytes.

workers_triggered_by: String

Operation that triggered the creation of the deployment.

computed Expand Collapse
id: String
author_email: String
created_on: Time
source: String

cloudflare_workers_deployment

resource "cloudflare_workers_deployment" "example_workers_deployment" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
  strategy = "percentage"
  versions = [{
    percentage = 100
    version_id = "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
  }]
  annotations = {
    workers_message = "Deploy bug fix."
  }
}

data cloudflare_workers_deployment

required Expand Collapse
deployment_id: String
account_id: String

Identifier.

script_name: String

Name of the script, used in URLs and route configuration.

computed Expand Collapse
id: String
author_email: String
created_on: Time
source: String
strategy: String
annotations: Attributes
workers_message: String

Human-readable message about the deployment. Truncated to 100 bytes.

workers_triggered_by: String

Operation that triggered the creation of the deployment.

versions: List[Attributes]
percentage: Float64
version_id: String

cloudflare_workers_deployment

data "cloudflare_workers_deployment" "example_workers_deployment" {
  account_id = "023e105f4ecef8ad9ca31a8372d0c353"
  script_name = "this-is_my_script-01"
  deployment_id = "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
}