Provides a Cloudflare worker script resource. In order for a script to be active, you'll also need to setup a cloudflare_worker_route
.
resource "cloudflare_workers_kv_namespace" "my_namespace" {
account_id = "f037e56e89293a057740de681ac9abbe"
title = "example"
}
# Sets the script with the name "script_1"
resource "cloudflare_worker_script" "my_script" {
account_id = "f037e56e89293a057740de681ac9abbe"
name = "script_1"
content = file("script.js")
kv_namespace_binding {
name = "MY_EXAMPLE_KV_NAMESPACE"
namespace_id = cloudflare_workers_kv_namespace.my_namespace.id
}
plain_text_binding {
name = "MY_EXAMPLE_PLAIN_TEXT"
text = "foobar"
}
secret_text_binding {
name = "MY_EXAMPLE_SECRET_TEXT"
text = var.secret_foo_value
}
webassembly_binding {
name = "MY_EXAMPLE_WASM"
module = filebase64("example.wasm")
}
service_binding {
name = "MY_SERVICE_BINDING"
service = "MY_SERVICE"
environment = "production"
}
r2_bucket_binding {
name = "MY_BUCKET"
bucket_name = "MY_BUCKET_NAME"
}
analytics_engine_binding {
name = "MY_DATASET"
dataset = "dataset1"
}
}
account_id
(String) The account identifier to target for the resource.content
(String) The script content.name
(String) The name for the script. Modifying this attribute will force creation of a new resource.analytics_engine_binding
(Block Set) (see below for nested schema)compatibility_date
(String) The date to use for the compatibility flag.compatibility_flags
(Set of String) Compatibility flags used for Worker Scripts.d1_database_binding
(Block Set) (see below for nested schema)dispatch_namespace
(String) Name of the Workers for Platforms dispatch namespace.kv_namespace_binding
(Block Set) (see below for nested schema)logpush
(Boolean) Enabling allows Worker events to be sent to a defined Logpush destination.module
(Boolean) Whether to upload Worker as a module.placement
(Block Set) (see below for nested schema)plain_text_binding
(Block Set) (see below for nested schema)queue_binding
(Block Set) (see below for nested schema)r2_bucket_binding
(Block Set) (see below for nested schema)secret_text_binding
(Block Set) (see below for nested schema)service_binding
(Block Set) (see below for nested schema)tags
(Set of String)webassembly_binding
(Block Set) (see below for nested schema)id
(String) The ID of this resource.analytics_engine_binding
Required:
dataset
(String) The name of the Analytics Engine dataset to write to.name
(String) The global variable for the binding in your Worker code.d1_database_binding
Required:
database_id
(String) Database ID of D1 database to use.name
(String) The global variable for the binding in your Worker code.kv_namespace_binding
Required:
name
(String) The global variable for the binding in your Worker code.namespace_id
(String) ID of the KV namespace you want to use.placement
Required:
mode
(String) The placement mode for the Worker. Available values: smart
.plain_text_binding
Required:
name
(String) The global variable for the binding in your Worker code.text
(String) The plain text you want to store.queue_binding
Required:
binding
(String) The name of the global variable for the binding in your Worker code.queue
(String) Name of the queue you want to use.r2_bucket_binding
Required:
bucket_name
(String) The name of the Bucket to bind to.name
(String) The global variable for the binding in your Worker code.secret_text_binding
Required:
name
(String) The global variable for the binding in your Worker code.text
(String, Sensitive) The secret text you want to store.service_binding
Required:
name
(String) The global variable for the binding in your Worker code.service
(String) The name of the Worker to bind to.Optional:
environment
(String) The name of the Worker environment to bind to.webassembly_binding
Required:
module
(String) The base64 encoded wasm module you want to store.name
(String) The global variable for the binding in your Worker code.Import is supported using the following syntax:
$ terraform import cloudflare_worker_script.example <account_id>/<script_name>