terraform-provider-cloudflare
terraform-provider-cloudflare copied to clipboard
`cloudflare_workers_custom_domain` requires environment however when deploying workers assets `environment` does not exist
Confirmation
- [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 v1.11.4 Cloudflare provider v5.4.0
Affected resource(s)
cloudflare_workers_custom_domain
Terraform configuration files
+ resource "cloudflare_workers_custom_domain" "worker-dev-worker-domain" {
+ account_id = "******"
+ environment = "production"
+ hostname = "static-site.example.com"
+ id = (known after apply)
+ service = "static-site"
+ zone_id = "*******"
+ zone_name = (known after apply)
}
Link to debug output
Panic output
│ Error: failed to make http request
│
│ with cloudflare_workers_custom_domain.static-site,
│ 90: }
│
│ PUT
│ "https://api.cloudflare.com/client/v4/accounts/******/workers/domains":
│ 404 Not Found {
│ "result": null,
│ "success": false,
│ "errors": [
│ {
│ "code": 10092,
│ "message": "This environment does not exist on this Worker."
│ }
│ ],
│ "messages": []
│ }
│
╵
Expected output
Custom domain on worker should be created successfully
Actual output
│ Error: failed to make http request
│
│ with cloudflare_workers_custom_domain.static-site,
│ 90: }
│
│ PUT
│ "https://api.cloudflare.com/client/v4/accounts/******/workers/domains":
│ 404 Not Found {
│ "result": null,
│ "success": false,
│ "errors": [
│ {
│ "code": 10092,
│ "message": "This environment does not exist on this Worker."
│ }
│ ],
│ "messages": []
│ }
│
╵
Steps to reproduce
-
Create a cloudflare worker assets using the steps here https://developers.cloudflare.com/workers/static-assets/get-started/#deploy-a-static-site. We use Terraform local exec to run
npx wrangler deploy -
Use cloudflare_workers_custom_domain to create static site custom domain record
Additional factoids
No response
References
No response
Hey there! Thank you for raising this issue! In order for the maintainers to fully diagnose you issue we need the full, unmodified output from TF_LOG=DEBUG which contains important context for debugging.
Also was this reproducible on v5.5?
I had the same error. You are likely missing environment = "production in your service binding.
{
type = "service",
name = "WORKER_SELF_REFERENCE",
environment = "production"
service = local.worker_name
},
Never mind, I actually still see that error after running apply, even with that env in the binding and the cloudflare_workers_custom_domain
My setup:
resource "cloudflare_workers_script" "name" {
...
bindings = [
{
type = "r2_bucket"
name = "NEXT_INC_CACHE_R2_BUCKET"
bucket_name = local.r2_bucket_name
},
{
type = "service",
name = "WORKER_SELF_REFERENCE",
environment = "production"
service = local.worker_name
},
{
type = "durable_object_namespace"
name = "NEXT_CACHE_DO_QUEUE"
class_name = local.do_queue_class
},
{
type = "durable_object_namespace"
name = "NEXT_TAG_CACHE_DO_SHARDED"
class_name = local.do_sharded_class
},
...
]
}
resource "cloudflare_workers_custom_domain" "craftcloud_worker_domain" {
account_id = module.cloudflare.cloudflare_account_id
zone_id = module.cloudflare.zone_id
hostname = local.app_domain
service = local.worker_name
environment = "production"
}
Cloudflare Worker "environments" are confusing. I was stuck on this, but I manually created a custom domain for a test deployment in the dashboard, and then used this API endpoint to discover the right service and environment values:
https://developers.cloudflare.com/api/resources/workers/subresources/domains/methods/get/
FTR, I haven't created an explicit WORKER_SELF_REFERENCE binding.
I have opened an issue internally to track this.
This issue hasn't been updated in a while. If it's still reproducing, please comment to let us know. Thank you!
I'm still having this problem. Any updates on this?