rules
Creates, updates, deletes, gets or lists a rules resource.
Overview
| Name | rules |
| Type | Resource |
| Id | cloudflare.rulesets.rules |
Fields
The following fields are returned by SELECT queries:
SELECT not supported for this resource, use SHOW METHODS to view available operations for the resource.
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
create_by_account | insert | ruleset_id, account_id | Adds a new rule to an account or zone ruleset. The rule will be added to the end of the existing list of rules in the ruleset by default. | |
create_by_zone | insert | ruleset_id, zone_id | Adds a new rule to an account or zone ruleset. The rule will be added to the end of the existing list of rules in the ruleset by default. | |
edit_by_account | update | rule_id, ruleset_id, account_id | Updates an existing rule in an account or zone ruleset. | |
edit_by_zone | update | rule_id, ruleset_id, zone_id | Updates an existing rule in an account or zone ruleset. | |
delete_by_account | delete | rule_id, ruleset_id, account_id | Deletes an existing rule from an account or zone ruleset. | |
delete_by_zone | delete | rule_id, ruleset_id, zone_id | Deletes an existing rule from an account or zone ruleset. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
account_id | string | The Cloudflare account ID. |
rule_id | string | The rule ID. |
ruleset_id | string | The ruleset ID. |
zone_id | string | The Cloudflare zone ID. |
INSERT examples
- create_by_account
- create_by_zone
- Manifest
Adds a new rule to an account or zone ruleset. The rule will be added to the end of the existing list of rules in the ruleset by default.
INSERT INTO cloudflare.rulesets.rules (
position,
action,
action_parameters,
description,
enabled,
exposed_credential_check,
expression,
id,
logging,
ratelimit,
ref,
ruleset_id,
account_id
)
SELECT
'{{ position }}',
'{{ action }}',
'{{ action_parameters }}',
'{{ description }}',
{{ enabled }},
'{{ exposed_credential_check }}',
'{{ expression }}',
'{{ id }}',
'{{ logging }}',
'{{ ratelimit }}',
'{{ ref }}',
'{{ ruleset_id }}',
'{{ account_id }}'
RETURNING
errors,
messages,
result,
success
;
Adds a new rule to an account or zone ruleset. The rule will be added to the end of the existing list of rules in the ruleset by default.
INSERT INTO cloudflare.rulesets.rules (
position,
action,
action_parameters,
description,
enabled,
exposed_credential_check,
expression,
id,
logging,
ratelimit,
ref,
ruleset_id,
zone_id
)
SELECT
'{{ position }}',
'{{ action }}',
'{{ action_parameters }}',
'{{ description }}',
{{ enabled }},
'{{ exposed_credential_check }}',
'{{ expression }}',
'{{ id }}',
'{{ logging }}',
'{{ ratelimit }}',
'{{ ref }}',
'{{ ruleset_id }}',
'{{ zone_id }}'
RETURNING
errors,
messages,
result,
success
;
# Description fields are for documentation purposes
- name: rules
props:
- name: ruleset_id
value: "{{ ruleset_id }}"
description: Required parameter for the rules resource.
- name: account_id
value: "{{ account_id }}"
description: Required parameter for the rules resource.
- name: zone_id
value: "{{ zone_id }}"
description: Required parameter for the rules resource.
- name: position
description: |
An object configuring where the rule will be placed.
value:
before: "{{ before }}"
after: "{{ after }}"
index: {{ index }}
- name: action
value: "{{ action }}"
description: |
The action to perform when the rule matches.
valid_values: ['block']
- name: action_parameters
description: |
The parameters configuring the rule's action.
value:
response:
content: "{{ content }}"
content_type: "{{ content_type }}"
status_code: {{ status_code }}
default: [object Object]
- name: description
value: "{{ description }}"
description: |
An informative description of the rule.
default:
- name: enabled
value: {{ enabled }}
description: |
Whether the rule should be executed.
default: true
- name: exposed_credential_check
description: |
Configuration for exposed credential checking.
value:
password_expression: "{{ password_expression }}"
username_expression: "{{ username_expression }}"
- name: expression
value: "{{ expression }}"
description: |
The expression defining which traffic will match the rule.
- name: id
value: "{{ id }}"
description: |
The unique ID of the rule.
- name: logging
description: |
An object configuring the rule's logging behavior.
value:
enabled: {{ enabled }}
- name: ratelimit
description: |
An object configuring the rule's rate limit behavior.
value:
characteristics:
- "{{ characteristics }}"
counting_expression: "{{ counting_expression }}"
mitigation_timeout: {{ mitigation_timeout }}
period: {{ period }}
requests_per_period: {{ requests_per_period }}
requests_to_origin: {{ requests_to_origin }}
score_per_period: {{ score_per_period }}
score_response_header_name: "{{ score_response_header_name }}"
- name: ref
value: "{{ ref }}"
description: |
The reference of the rule (the rule's ID by default).
UPDATE examples
- edit_by_account
- edit_by_zone
Updates an existing rule in an account or zone ruleset.
UPDATE cloudflare.rulesets.rules
SET
position = '{{ position }}',
action = '{{ action }}',
action_parameters = '{{ action_parameters }}',
description = '{{ description }}',
enabled = {{ enabled }},
exposed_credential_check = '{{ exposed_credential_check }}',
expression = '{{ expression }}',
id = '{{ id }}',
logging = '{{ logging }}',
ratelimit = '{{ ratelimit }}',
ref = '{{ ref }}'
WHERE
rule_id = '{{ rule_id }}' --required
AND ruleset_id = '{{ ruleset_id }}' --required
AND account_id = '{{ account_id }}' --required
RETURNING
errors,
messages,
result,
success;
Updates an existing rule in an account or zone ruleset.
UPDATE cloudflare.rulesets.rules
SET
position = '{{ position }}',
action = '{{ action }}',
action_parameters = '{{ action_parameters }}',
description = '{{ description }}',
enabled = {{ enabled }},
exposed_credential_check = '{{ exposed_credential_check }}',
expression = '{{ expression }}',
id = '{{ id }}',
logging = '{{ logging }}',
ratelimit = '{{ ratelimit }}',
ref = '{{ ref }}'
WHERE
rule_id = '{{ rule_id }}' --required
AND ruleset_id = '{{ ruleset_id }}' --required
AND zone_id = '{{ zone_id }}' --required
RETURNING
errors,
messages,
result,
success;
DELETE examples
- delete_by_account
- delete_by_zone
Deletes an existing rule from an account or zone ruleset.
DELETE FROM cloudflare.rulesets.rules
WHERE rule_id = '{{ rule_id }}' --required
AND ruleset_id = '{{ ruleset_id }}' --required
AND account_id = '{{ account_id }}' --required
;
Deletes an existing rule from an account or zone ruleset.
DELETE FROM cloudflare.rulesets.rules
WHERE rule_id = '{{ rule_id }}' --required
AND ruleset_id = '{{ ruleset_id }}' --required
AND zone_id = '{{ zone_id }}' --required
;