Cache Rules and Terraform

Is it possible to configure Cache Rules through Terraform?

The documentation mentions Terraform explicitly but I can’t find a specific resource for that.

https://blog.cloudflare.com/introducing-cache-rules

1 Like

Got a reply in the GitHub repository: https://github.com/cloudflare/terraform-provider-cloudflare/issues/2022#issuecomment-1311623458

you'll need to checkout the [developer docs](https://developers.cloudflare.com/cache/about/cache-rules/#create-cache-rules-via-api) and [provider docs](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/ruleset) to build the resource for your cache settings.

If you want an example then I have this

resource "cloudflare_ruleset" "dont_cache_pages_domains" {
  zonezone_id =  var.zone_id
  kind       = "zone"
  name       = "default"
  phase      = "http_request_cache_settings"
  rules {
    action      = "set_cache_settings"
    description = "Don't cache pages"
    enabled     = true
    expression  = "(http.host eq \"cf-api.cyberjake.xyz\") or (http.host eq \"cyberjake.xyz\") or (http.host eq \"www.cyberjake.xyz\") or (http.host eq \"blog.cyberjake.xyz\")"
    action_parameters {
      cache = false
    }
  }
}