Skip to content

cloudflare_worker: Creating a Worker via Terraform does not connect Git repository — Builds Git integration must be done manually #6924

Description

@heiba

Confirmation

  • This is a bug with an existing resource and is not a feature request or enhancement. Feature requests should be submitted with Cloudflare Support or your account team.
  • I have searched the issue tracker and my issue isn't already found.
  • I have replicated my issue using the latest version of the provider and it is still present.

Terraform and Cloudflare provider version

Terraform v1.14.6
on darwin_arm64

cloudflare = {
    source  = "cloudflare/cloudflare"
    version = "~> 5.18.0"
}

Affected resource(s)

  • cloudflare_worker

Terraform configuration files

resource "cloudflare_worker" "branding_web" {
  account_id = var.cloudflare_account_id
  name       = "my-worker"
 
  observability = {
    enabled = true
    logs    = { enabled = true }
  }
}

Link to debug output

https://gist.github.com/heiba/0be646eefcf3e8d7f7968861a934513e

Panic output

No response

Expected output

After creating a Worker via Terraform, I should be able to specify a GitHub repository, branch, and build/deploy commands so that the Worker is automatically connected to Git for Workers Builds. The Git connection should show as connected in Settings > Builds > Git repository in the dashboard, and pushes to the configured branch should trigger automated builds and deployments.

The cloudflare_worker resource (or a companion resource) should support something like:

resource "cloudflare_worker" "branding_web" {
  account_id = var.cloudflare_account_id
  name       = "my-worker"
 
  # Git integration for Workers Builds
  builds = {
    provider_type         = "github"
    provider_account_name = "my-org"
    provider_account_id   = "12345678"
    repo_name             = "my-worker-repo"
    repo_id               = "87654321"
    branch                = "main"
    build_command          = "npm run build"
    deploy_command         = "npx wrangler deploy"
  }
}

This is consistent with how cloudflare_pages_project handles Git integration via its source block — the expectation is that Workers should have parity.

Actual output

The Worker is created successfully, but there is no way to connect it to a Git repository through Terraform. After terraform apply, the Worker's Settings > Builds > Git repository still shows "Connect" with no repository linked:

Workers Builds Git repository shows "Connect" — not connected after Terraform apply

Image

The Git integration can only be completed by:

  1. Manually clicking "Connect" in the Cloudflare dashboard, or
  2. Using terraform_data with local-exec provisioners that shell out to curl against the undocumented-in-Terraform Builds API — which does not track state, cannot detect drift, is not idempotent, and requires curl/jq as runtime dependencies.

This means the Git connection is the only part of the Worker setup that cannot be managed via Terraform, breaking the IaC workflow.

Steps to reproduce

  1. Create a cloudflare_worker resource via Terraform
  2. Run terraform apply — Worker is created successfully
  3. Open the Worker in the Cloudflare dashboard → Settings > Builds
  4. Observe that Git repository is not connected — it shows "Connect"
  5. The only way to connect it is manually via the dashboard or raw API calls

Additional factoids

  • The Builds API fully supports managing this programmatically (tokens, repo connections, triggers), but the Terraform provider does not expose any of it.
  • cloudflare_pages_project already supports Git integration via its source block. Workers Builds is the Workers-side equivalent and should have the same Terraform support.
  • The Workers IaC documentation covers cloudflare_worker, cloudflare_worker_version, and cloudflare_workers_deployment but makes no mention of Workers Builds or Git integration.

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.version/5Categorizes issue or PR as related to version 5 of the provider.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions