Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow uploading Workers to dispatch namespaces + tags #3154

Merged

Conversation

WalshyDev
Copy link
Member

@WalshyDev WalshyDev commented Feb 29, 2024

Allows uploading to a Workers for Platforms namespace and with tags.

Example Terraform file:

resource "cloudflare_workers_for_platforms_dispatch_namespace" "namespace" {
  account_id = var.account_id
  name = "test-tf"
}

resource "cloudflare_worker_script" "dispatch_worker" {
  account_id = var.account_id
  name       = "test-dispatch-worker"
  module = true

  content    = <<EOF
  export default {
    fetch(req, env) {
      try {
        const whatWorker = req.headers.get('x-worker');
        if (whatWorker === null) {
          return new Response('404');
        }

        const worker = env.NAMESPACE.get(whatWorker);

        return worker.fetch(req)
          .catch(e => {
            if (e.message === 'Worker not found') {
              return new Response('Worker not found');
            } else {
              return new Response(e.message + '\n' + e.stack);
            }
          });
      } catch(e) {
        return new Response(e.message + '\n' + e.stack);
      }
    }
  }
  EOF
}

resource "cloudflare_worker_script" "user_worker" {
  account_id = var.account_id
  name       = "user-worker"
  dispatch_namespace = "test-tf"
  module = true
  tags = ["free"]

  content    = <<EOF
  export default {
    fetch(req, env) {
      return Response.json(env);
      // return new Response('Hello, World');
    }
  }
  EOF
}

@WalshyDev WalshyDev force-pushed the walshy/add-wfp-to-workers-script branch from 68765f6 to e15e4d2 Compare March 13, 2024 07:10
Copy link
Contributor

github-actions bot commented Mar 13, 2024

changelog detected ✅

@jacobbednarz
Copy link
Member

the cloudflare-go update landed this morning. as long as you've cut a branch of recent master, you should be good to go.

@WalshyDev
Copy link
Member Author

Yep, rebased on top and builds are passing now. Gonna do another change and retest today

@WalshyDev WalshyDev marked this pull request as ready for review March 14, 2024 13:07
@WalshyDev WalshyDev requested a review from jacobbednarz as a code owner March 14, 2024 13:07
@jacobbednarz
Copy link
Member

lgtm and the acceptance test suite

TF_ACC=1 go test ./internal/sdkv2provider -v -run "^TestAccCloudflareWorkerScript_" -count 1 -timeout 120m -parallel 1
=== RUN   TestAccCloudflareWorkerScript_Import
--- PASS: TestAccCloudflareWorkerScript_Import (13.74s)
=== RUN   TestAccCloudflareWorkerScript_MultiScriptEnt
=== PAUSE TestAccCloudflareWorkerScript_MultiScriptEnt
=== RUN   TestAccCloudflareWorkerScript_ModuleUpload
=== PAUSE TestAccCloudflareWorkerScript_ModuleUpload
=== CONT  TestAccCloudflareWorkerScript_MultiScriptEnt
--- PASS: TestAccCloudflareWorkerScript_MultiScriptEnt (44.18s)
=== CONT  TestAccCloudflareWorkerScript_ModuleUpload
--- PASS: TestAccCloudflareWorkerScript_ModuleUpload (19.72s)
PASS
ok  	github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider	78.778s

(fix from #3188 handled the unrelated failure initially seen here)

@jacobbednarz jacobbednarz merged commit 64b49c1 into cloudflare:master Mar 15, 2024
10 checks passed
@github-actions github-actions bot added this to the v4.27.0 milestone Mar 15, 2024
github-actions bot pushed a commit that referenced this pull request Mar 15, 2024
@WalshyDev WalshyDev deleted the walshy/add-wfp-to-workers-script branch March 15, 2024 08:00
Copy link
Contributor

This functionality has been released in v4.27.0 of the Terraform Cloudflare Provider.

Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants