[X] 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.
[X] I have searched the issue tracker and my issue isn't already found.
[X] I have replicated my issue using the latest version of the provider and it is still present.
Terraform and Cloudflare provider version
terraform_version: 1.6.4
Affected resource(s)
cloudflare_worker_cron_trigger
Terraform configuration files
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 4"
}
}
}
provider "cloudflare" {
# read token from $CLOUDFLARE_API_TOKEN
}
variable "CLOUDFLARE_ACCOUNT_ID" {
# read account id from $TF_VAR_CLOUDFLARE_ACCOUNT_ID
type = string
}
resource "cloudflare_workers_kv_namespace" "uptimeflare_kv" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
title = "uptimeflare_kv"
}
resource "cloudflare_worker_script" "uptimeflare" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare_worker"
content = file("worker/dist/index.js")
module = true
compatibility_date = "2023-11-08"
kv_namespace_binding {
name = "UPTIMEFLARE_STATE"
namespace_id = cloudflare_workers_kv_namespace.uptimeflare_kv.id
}
}
resource "cloudflare_worker_cron_trigger" "uptimeflare_worker_cron" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
script_name = cloudflare_worker_script.uptimeflare.name
schedules = [
"* * * * *", # every 1 minute, you can reduce the KV write by increase the worker settings of `kvWriteCooldownMinutes`
]
}
resource "cloudflare_pages_project" "uptimeflare" {
account_id = var.CLOUDFLARE_ACCOUNT_ID
name = "uptimeflare"
production_branch = "main"
deployment_configs {
production {
kv_namespaces = {
UPTIMEFLARE_STATE = cloudflare_workers_kv_namespace.uptimeflare_kv.id
}
compatibility_date = "2023-11-08"
compatibility_flags = ["nodejs_compat"]
}
}
}
Terraform should create the CRON Trigger without problems.
Actual output
Creation failed with workers.api.error.subdomain_required
Steps to reproduce
Create a new Cloudflare Account
terraform init
terraform apply
Additional factoids
This problem only happens with new Cloudflare Accounts (Hasn't setup any Workers before, without setting up a Worker domain)
There seems to be an inconsistency in the behavior of the API: if a Cloudflare account has never created any Workers, a newly created Worker by Terraform will not be able to set the CRON Trigger due to the above error
Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
Volunteering to Work on This Issue
If you are interested in working on this issue, please leave a comment.
If this would be your first contribution, please review the contribution guide.
Confirmation
Terraform and Cloudflare provider version
terraform_version: 1.6.4
Affected resource(s)
cloudflare_worker_cron_trigger
Terraform configuration files
Link to debug output
https://gist.github.com/lyc8503/c6b82f173d6fde370fbb2b1331dae7d9
Panic output
No response
Expected output
Terraform should create the CRON Trigger without problems.
Actual output
Creation failed with
workers.api.error.subdomain_required
Steps to reproduce
terraform init
terraform apply
Additional factoids
This problem only happens with new Cloudflare Accounts (Hasn't setup any Workers before, without setting up a Worker domain)
There seems to be an inconsistency in the behavior of the API: if a Cloudflare account has never created any Workers, a newly created Worker by Terraform will not be able to set the CRON Trigger due to the above error
References
No response