terraform-provider-cloudflare
terraform-provider-cloudflare copied to clipboard
Support environments with Terraform
Current Terraform and Cloudflare provider version
Terraform v0.15.4
Description
Hi
I couldn't find anything in the documentation which indicates that I can create and use environments for workers through terraform. https://developers.cloudflare.com/workers/platform/environments mentions it is only possible through Wrangler. Please let me know if there is a way or plan to support that.
For now, I have created separate workers for each of our environments, but would definitely prefer any way to just create 1 worker and manage different environments for it.
Use cases
We have different development environments and would like worker environments to match our environment.
Potential Terraform configuration
resource "cloudflare_worker_environment" "my-env" {
name = "staging"
}
resource "cloudflare_worker_script" "my-script" {
name = "my-script"
environment = cloudflare_worker_environment.my-env.id
}
References
No response
Seems this is not supported by terraform, because you can't work with environment's via API. I didn't find any way to specify env for a new worker deploy, as for example: https://api.cloudflare.com/#worker-routes-properties
My understanding is that the environments are more like completely different scripts that happen to have the same name and are thus grouped together in the UX. When a script is uploaded, and two scripts have the same name but different environments, that's when the UX does its magic entirely in the client-side browser JS.
On the API side of things, each one is uploaded as a complete set of script + variables + bindings + routes. Nothing is inherited from a "base" environment on the backend; wrangler may make it look this way, but in fact it's a client-side convenience.
This issue has been closed as we are now tracking this internally with service teams directly. If you would like an update or to be notified when/if the product ships with this change, please reach out to Cloudflare Support or your account team who can watch the internal feature request for you.