Skip to content

Conversation

@aleksandar-kinanov
Copy link

@aleksandar-kinanov aleksandar-kinanov commented Oct 6, 2025

  • I understand that this repository is auto-generated and my pull request may not be merged

Summary

The PR introduces rule under ruleset as standalone object, i.e. the lifecycle of the object is independent of the lifecycle of the ruleset object. This allows for easier customisation of the rule object outside of the ruleset itself.

Co-Author: @stefan-todorov

Key Features

  1. Adds CRUD for rule object
  2. Adds Resource/Datasource for rule object

Usage example

variable "zone_id" {}

resource "cloudflare_ruleset" "block_external_traffic" {
  kind    = "zone"
  name    = "Block external traffic"
  phase   = "http_request_firewall_custom"
  zone_id = var.zone_id
  lifecycle {
    ignore_changes = [rules]
  }
}

resource "cloudflare_ruleset_rule" "allow_rancher" {
  ruleset_id  = cloudflare_ruleset.block_external_traffic.id
  action      = "skip"
  action_parameters = {
    ruleset = "current"
  }
  enabled     = true
  expression  = "(starts_with(http.host, \"provisioning\") and ip.src eq 151.251.76.61)"

  zone_id = var.zone_id
  position = {
    index = 1
  }
}

Blockers

Currently, if applied secondary time while specifying position, the PATCH operation against:

/{accounts_or_zones}/{account_or_zone_id}/rulesets/{ruleset_id}/rules/{rule_id}

Throws the following error:

        PATCH
     "https://api.cloudflare.com/client/v4/zones/0872c3ad561815a48219d75f13b4f126/rulesets/fbc8242f68644212a6492398ab5b3dd7/rules/b0b748c1a0bd4a978dae3f005dffca88":
        400 Bad Request {
          "result": null,
          "success": false,
          "errors": [
            {
              "code": 20011,
              "message": "'1' is not a valid value for index because the rule is already in that position",
              "source": {
                "pointer": "/position/index"
              }
            }
          ],
          "messages": []

This prevents us from covering with tests, but it is also usage blocker.

We believe there should be an API change rather than workaround in the code. Let's open a discussion about it and see how to move forward

@aleksandar-kinanov aleksandar-kinanov marked this pull request as draft October 6, 2025 13:48
@aleksandar-kinanov aleksandar-kinanov changed the title Adds ruleset rule as standalone object instead of element in list und… feat: Adds ruleset rule as standalone object instead of element in list und… Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant