Define a single origin rule using Terraform
Create an origin rule using Terraform to override the Host header, the resolved hostname, and the destination port of API requests.
The following example defines a single origin rule for a zone using Terraform. The rule overrides the Host header, the resolved hostname, and the destination port of API requests.
# Change origin for API requestsresource "cloudflare_ruleset" "http_origin_example" {  zone_id     = "<ZONE_ID>"  name        = "Change origin"  description = ""  kind        = "zone"  phase       = "http_request_origin"
  rules {    ref         = "change_api_origin"    description = "Change origin of API requests"    expression  = "(http.request.uri.path matches \"^/api/\")"    action      = "route"    action_parameters {      host_header = "example.net"      origin {        host = "example.net"        port = 8000      }    }  }}For additional guidance on using Terraform with Cloudflare, refer to the following resources:
- Terraform documentation
- Cloudflare Provider for Terraform ↗ (reference documentation)
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark