If your organization uses Cloudflare, you can use HUMAN’s Cloudflare Enforcer to protect against malicious behavior. The Cloudflare Enforcer is installed using a Cloudflare Worker, or a snippet of code, and is deployed to your content delivery network (CDN). The Enforcer dictates how traffic should be handled per your organization’s standards.
You can learn how to install the Cloudflare Enforcer using the Cloudflare Terraform provider with this guide.
For other installation options, see:
terraform apply (not required when use_prebuilt = true or use_custom_worker = true):
nvm install stable in your CLI to install it.npm install -g wrangler in your CLI to install it.The Terraform module uses the following files. Refer to the detailed file information for more on the highlighted files.
.gitignore directory:terraform.tfvars file in your Terraform module directory, and ensure terraform.tfvars or *.tfvars is listed in .gitignore so Git does not track it.Never commit this file! Ensure to include it in .gitignore.
Commit the generated .terraform.lock.hcl to version control. This locks provider versions and ensures reproducible applies across machines and CI runs.
If you have an existing Cloudflare Worker, KV namespace, or routes that were previously deployed, import them into the Terraform state:
To deploy, run:
After deploying, Terraform will:
enforcer_config to worker/src/config.jsonnpm install, then wrangler deploy --dry-run inside worker/When complete, you’ll see:
To see kv_namespace_id, run:
You can update the Enforcer using the available configurations. To do so:
terraform.tfvars file with the appropriate configuration updates.terraform apply:We recommend using use_prebuilt=true particularly when changing enforcer_config. When set to false, the null_resource rebuilds dist/index.js during terraform apply after the plan has already locked the file’s SHA-256. This causes a “provider inconsistency” error on the first run and requires a second terraform apply -var-file="terraform.tfvars" to complete. Using use_prebuilt = true avoids this by separating build from deploy.
Assuming only enforcer_config changed, Terraform will:
worker/src/config.json. Changing the configuration hash always triggers a rebuild.No manual rebuild or Cloudflare console steps are needed.
To remove all Cloudflare resources managed by this module, run:
The worker/dist/ directory and worker/node_modules/ are local build artifacts and aren’t removed by terraform destroy. Delete them manually if needed.
On subsequent runs, Terraform only rebuilds and re-uploads what actually changed. The build step is skipped unless enforcer_config, a Worker source file (src/*.ts), wrangler.toml, tsconfig.json, package.json, or package-lock.json has changed (all tracked via SHA-256 triggers).