Skip to content

Commit

Permalink
fix(cloudflare_worker): add missing js module option to fix upload
Browse files Browse the repository at this point in the history
  • Loading branch information
js0cha committed Aug 26, 2022
1 parent b2cee3b commit b003edc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1849.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_worker: provide js module option to allow service bindings
```
2 changes: 2 additions & 0 deletions docs/resources/worker_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "cloudflare_workers_kv_namespace" "my_namespace" {
resource "cloudflare_worker_script" "my_script" {
name = "script_1"
content = file("script.js")
module_enabled = true
kv_namespace_binding {
name = "MY_EXAMPLE_KV_NAMESPACE"
Expand Down Expand Up @@ -59,6 +60,7 @@ The following arguments are supported:

- `name` - (Required) The name for the script.
- `content` - (Required) The script content.
- `module_enabled` - (Optional) Default: false. Allow upload of js-module worker.

**kv_namespace_binding** supports:

Expand Down
12 changes: 12 additions & 0 deletions internal/provider/resource_cloudflare_worker_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func resourceCloudflareWorkerScriptCreate(ctx context.Context, d *schema.Resourc
return diag.FromErr(fmt.Errorf("script content cannot be empty"))
}

moduleEnabled := d.Get("module_enabled").(bool)
if moduleEnabled == nil {
moduleEnabled = false
}

tflog.Info(ctx, fmt.Sprintf("Creating Cloudflare Worker Script from struct: %+v", &scriptData.Params))

bindings := make(ScriptBindings)
Expand All @@ -137,6 +142,7 @@ func resourceCloudflareWorkerScriptCreate(ctx context.Context, d *schema.Resourc

scriptParams := cloudflare.WorkerScriptParams{
Script: scriptBody,
Module: moduleEnabled,
Bindings: bindings,
}

Expand Down Expand Up @@ -277,6 +283,11 @@ func resourceCloudflareWorkerScriptUpdate(ctx context.Context, d *schema.Resourc
return diag.FromErr(fmt.Errorf("script content cannot be empty"))
}

moduleEnabled := d.Get("module_enabled").(bool)
if moduleEnabled == nil {
moduleEnabled = false
}

tflog.Info(ctx, fmt.Sprintf("Updating Cloudflare Worker Script from struct: %+v", &scriptData.Params))

bindings := make(ScriptBindings)
Expand All @@ -285,6 +296,7 @@ func resourceCloudflareWorkerScriptUpdate(ctx context.Context, d *schema.Resourc

scriptParams := cloudflare.WorkerScriptParams{
Script: scriptBody,
Module: moduleEnabled,
Bindings: bindings,
}

Expand Down

0 comments on commit b003edc

Please sign in to comment.