Hi I’m wondering about cloudflare container suppor...
# general
d
Hi I’m wondering about cloudflare container support. I found this discussion on gh that directed users to this slack but I could not find anything regarding Coudflare Containers. Thanks!
👀 1
h
Hi! the pulumi provider is based on the upstream terraform cloudflare provider, which unfortunately doesn't seem to have support a container application resource yet. It looks like there was a PR to add support, but it got closed. I'm not sure what the status is, might be worth asking upstream (Apparently this provider is auto-generated from Cloudflare's published OpenAPI spec. Since the feature just went GA a couple weeks ago, I expect there is just some lag in the spec being updated.)
In the meantime you could potentially work around this using the Command provider to wrap the necessary wrangler commands. Here is a sketch:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as command from "@pulumi/command";
import * as fs from "fs";

// The wrangler project lives alongside or within the Pulumi project
const workerDir = "./my-container-worker";

// Hash the source files so the command re-runs on changes
const sourceHash = pulumi.output(
    fs.readdirSync(workerDir)
        .filter(f => f.match(/\.(ts|js|jsonc?)$/))
        .map(f => fs.readFileSync(`${workerDir}/${f}`, "utf-8"))
        .join("\n")
).apply(s => require("crypto").createHash("sha256").update(s).digest("hex"));

const deploy = new command.local.Command("container-worker", {
    dir: workerDir,
    create: "wrangler deploy",
    update: "wrangler deploy",
    delete: "wrangler delete",
    environment: {
        CLOUDFLARE_API_TOKEN: cfg.requireSecret("cloudflareApiToken"),
    },
    triggers: [sourceHash],
});
And the corresponding wrangler.jsonc in ./my-container-worker/:
Copy code
{
  "name": "my-container-worker",
  "main": "src/index.ts",
  "compatibility_date": "2025-04-01",
  "durable_objects": {
    "bindings": [
      {
        "name": "MY_CONTAINER",
        "class_name": "MyContainer"
      }
    ]
  },
  "migrations": [
    {
      "tag": "v1",
      "new_sqlite_classes": [
        "MyContainer"
      ]
    }
  ],
  "containers": [
    {
      "class_name": "MyContainer",
      "image": "docker.io/library/nginx:latest",
      "instance_type": "basic",
      "max_instances": 5
    }
  ]
}
this will it'll automatically run
wrangler deploy
for you when you pulumi up and your container definition has changed.
🙌 1
d
thank you very much for the detailed reply! I did not know about command provider. I'm new to terraform/pulumi and first searched "containers" in the cf terraform provider and found this, but I’m not sure if that manages the container or just the do it's attached to. will try this weekend and update thread with findings
h
I think that property is how you will end up attaching a container to a worker, once the provider is updated, but it seems that the resource for actually defining what that container is is not yet available
d
makes sense. thank you!