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

Error deploying with Terraform #77

Open
imjasonh opened this issue Dec 30, 2023 · 0 comments
Open

Error deploying with Terraform #77

imjasonh opened this issue Dec 30, 2023 · 0 comments

Comments

@imjasonh
Copy link

I'm trying to get this (Very helpful! Thank you!) package to integrate with a Terraform workflow, instead of deploying using wrangler publish.

Here's what I've managed to get so far:

resource "terraform_data" "build" {
  # Changes to *.go files requires re-building it.
  input = {
    # https://stackoverflow.com/questions/51138667/can-terraform-watch-a-directory-for-changes
    dir_sha1 = sha1(join("", [for f in fileset("${path.module}", "*.go") : filesha1("${path.module}/${f}")]))
  }

  provisioner "local-exec" {
    command = <<EOC
go run github.com/syumai/workers/cmd/[email protected] -mode=go
GOOS=js GOARCH=wasm go build -o ./build/app.wasm .
EOC
  }
}

resource "cloudflare_worker_script" "script" {
  depends_on = [terraform_data.build]
  account_id = var.cloudflare_account_id
  name       = var.name
  content    = file("${path.module}/build/worker.mjs")

  // │ Error: error creating worker script: Wasm and blob bindings are not supported with modules; use imports instead (10021)
  module = false

  webassembly_binding {
    name   = "WASM"
    module = filebase64("./build/app.wasm")
  }
}

Refs:

This basically says "run the script to build app.wasm, then deploy the worker script with it as a binding". There's some quirks I still need to work out with TF lifecycle to ensure it builds before trying to take the filebase64, but that's not the bug I'm currently hitting.

The bug I'm hitting is that, whether or not I use the local-exec trick, deploying the script fails with:

╷
│ Error: error creating worker script: Uncaught SyntaxError: Cannot use import statement outside a module
│   at worker.js:1
│  (10021)
│ 
│   with cloudflare_worker_script.script,
│   on main.tf line 18, in resource "cloudflare_worker_script" "script":
│   18: resource "cloudflare_worker_script" "script" {
│ 

Digging around, it might be the case that the TF provider just doesn't support WASM workers, even though it claims to: cloudflare/terraform-provider-cloudflare#2039

I guess I'm opening this in case anybody's gotten this to work with this package, or understands the error message well enough to give any hints about what might be happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant