Skip to content

Commit 1b8e916

Browse files
committed
[Docs] Review cloudflare_ruleset Terraform examples
1 parent 8f8b7d5 commit 1b8e916

File tree

9 files changed

+195
-195
lines changed

9 files changed

+195
-195
lines changed

src/content/docs/cache/how-to/cache-rules/terraform-example.mdx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ sidebar:
66
head:
77
- tag: title
88
content: Cache Rules — Terraform example
9-
109
---
1110

12-
import { Details } from "~/components"
11+
import { Details } from "~/components";
1312

1413
The following example defines a single cache rule for a zone using Terraform. The rule configures several cache settings and sets a custom cache key for incoming requests addressed at `example.net`.
1514

16-
1715
<Details header="Terraform `cloudflare_ruleset` resource">
1816

1917
```tf
@@ -26,7 +24,10 @@ resource "cloudflare_ruleset" "cache_rules_example" {
2624
phase = "http_request_cache_settings"
2725
2826
rules {
29-
action = "set_cache_settings"
27+
ref = "cache_settings_custom_cache_key"
28+
description = "Set cache settings and custom cache key for example.net"
29+
expression = "(http.host eq \"example.net\")"
30+
action = "set_cache_settings"
3031
action_parameters {
3132
edge_ttl {
3233
mode = "override_origin"
@@ -77,14 +78,10 @@ resource "cloudflare_ruleset" "cache_rules_example" {
7778
}
7879
origin_error_page_passthru = false
7980
}
80-
expression = "(http.host eq \"example.net\")"
81-
description = "Set cache settings and custom cache key for example.net"
82-
enabled = true
8381
}
8482
}
8583
```
8684

87-
8885
</Details>
8986

9087
For additional guidance on using Terraform with Cloudflare, refer to [Terraform](/terraform/).

src/content/docs/rules/configuration-rules/examples/define-single-configuration-terraform.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ resource "cloudflare_ruleset" "http_config_rules_example" {
2323
phase = "http_config_settings"
2424
2525
rules {
26-
action = "set_config"
26+
ref = "disable_obfuscation_bic"
27+
description = "Disable email obfuscation and BIC for API requests"
28+
expression = "(http.request.uri.path matches \"^/api/\")"
29+
action = "set_config"
2730
action_parameters {
2831
email_obfuscation = false
2932
bic = false
3033
}
31-
expression = "(http.request.uri.path matches \"^/api/\")"
32-
description = "Disable email obfuscation and BIC for API requests"
33-
enabled = true
3434
}
3535
}
3636
```

src/content/docs/rules/origin-rules/examples/define-single-origin-terraform.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ resource "cloudflare_ruleset" "http_origin_example" {
2323
phase = "http_request_origin"
2424
2525
rules {
26-
action = "route"
26+
ref = "change_api_origin"
27+
description = "Change origin of API requests"
28+
expression = "(http.request.uri.path matches \"^/api/\")"
29+
action = "route"
2730
action_parameters {
2831
host_header = "example.net"
2932
origin {
3033
host = "example.net"
3134
port = 8000
3235
}
3336
}
34-
expression = "(http.request.uri.path matches \"^/api/\")"
35-
description = "Change origin of API requests"
36-
enabled = true
3737
}
3838
}
3939
```

src/content/docs/rules/url-forwarding/single-redirects/terraform-example.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ resource "cloudflare_ruleset" "single_redirects_example" {
2020
phase = "http_request_dynamic_redirect"
2121
2222
rules {
23-
action = "redirect"
23+
ref = "redirect_old_url"
24+
description = "Redirect visitors still using old URL"
25+
expression = "(http.request.uri.path matches \"^/contact-us/\")"
26+
action = "redirect"
2427
action_parameters {
2528
from_value {
2629
status_code = 301
@@ -30,9 +33,6 @@ resource "cloudflare_ruleset" "single_redirects_example" {
3033
preserve_query_string = false
3134
}
3235
}
33-
expression = "(http.request.uri.path matches \"^/contact-us/\")"
34-
description = "Redirect visitors still using old URL"
35-
enabled = true
3636
}
3737
}
3838
```

src/content/docs/terraform/additional-configurations/ddos-managed-rulesets.mdx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ resource "cloudflare_ruleset" "zone_level_http_ddos_config" {
4545
phase = "ddos_l7"
4646
4747
rules {
48-
action = "execute"
48+
ref = "override_l7_ddos_ruleset_all"
49+
description = "Override the HTTP DDoS Attack Protection managed ruleset"
50+
expression = "true"
51+
action = "execute"
4952
action_parameters {
5053
# Cloudflare L7 DDoS Attack Protection Ruleset
5154
id = "4d21379b4f9f4bb088e0729962c8b3cf"
5255
overrides {
5356
rules {
5457
# Rule: HTTP requests with unusual HTTP headers or URI path (signature #11).
55-
id = "fdfdac75430c4c47a959592f0aa5e68a"
58+
id = "fdfdac75430c4c47a959592f0aa5e68a"
5659
sensitivity_level = "low"
5760
}
5861
}
5962
}
60-
expression = "true"
61-
description = "Override the HTTP DDoS Attack Protection managed ruleset"
62-
enabled = true
6363
}
6464
}
6565
```
@@ -86,21 +86,21 @@ resource "cloudflare_ruleset" "account_level_network_ddos_config" {
8686
phase = "ddos_l4"
8787
8888
rules {
89-
action = "execute"
89+
ref = "override_l7_ddos_ruleset_dst_ip"
90+
description = "Override the HTTP DDoS Attack Protection managed ruleset"
91+
expression = "ip.dst in { 192.0.2.0/24 }"
92+
action = "execute"
9093
action_parameters {
9194
# Cloudflare L3/4 DDoS Attack Protection Ruleset
9295
id = "3b64149bfa6e4220bbbc2bd6db589552"
9396
overrides {
9497
rules {
9598
# Rule: Generic high-volume UDP traffic flows.
96-
id = "599dab0942ff4898ac1b7797e954e98b"
99+
id = "599dab0942ff4898ac1b7797e954e98b"
97100
sensitivity_level = "low"
98101
}
99102
}
100103
}
101-
expression = "ip.dst in { 192.0.2.0/24 }"
102-
description = "Override the HTTP DDoS Attack Protection managed ruleset"
103-
enabled = true
104104
}
105105
}
106106
```
@@ -159,53 +159,53 @@ resource "cloudflare_ruleset" "zone_level_http_ddos_config" {
159159
# level.
160160
161161
rules {
162+
ref = "l7_ddos_block_traffic_low_threshold"
162163
description = "At the low sensitivity threshold, block the traffic"
163-
action = "execute"
164+
expression = "true"
165+
action = "execute"
164166
action_parameters {
165167
# Cloudflare L7 DDoS Attack Protection Ruleset
166168
id = "4d21379b4f9f4bb088e0729962c8b3cf"
167169
overrides {
168170
rules {
169171
# Rule: HTTP requests from known botnet (signature #4).
170-
id = "29d170ba2f004cc787b1ac272c9e04e7"
172+
id = "29d170ba2f004cc787b1ac272c9e04e7"
171173
sensitivity_level = "low"
172-
action = "block"
174+
action = "block"
173175
}
174176
rules {
175177
# Rule: HTTP requests with unusual HTTP headers or URI path (signature #16).
176-
id = "60a48054bbcf4014ac63c44f1712a123"
178+
id = "60a48054bbcf4014ac63c44f1712a123"
177179
sensitivity_level = "low"
178-
action = "block"
180+
action = "block"
179181
}
180182
}
181183
}
182-
expression = "true"
183-
enabled = true
184184
}
185185
186186
rules {
187+
ref = "l7_ddos_log_default_threshold"
187188
description = "At the default sensitivity threshold, log to see if any legitimate traffic gets caught"
188-
action = "execute"
189+
expression = "true"
190+
action = "execute"
189191
action_parameters {
190192
# Cloudflare L7 DDoS Attack Protection Ruleset
191193
id = "4d21379b4f9f4bb088e0729962c8b3cf"
192194
overrides {
193195
rules {
194196
# Rule: HTTP requests from known botnet (signature #4).
195-
id = "29d170ba2f004cc787b1ac272c9e04e7"
197+
id = "29d170ba2f004cc787b1ac272c9e04e7"
196198
sensitivity_level = "default"
197-
action = "log"
199+
action = "log"
198200
}
199201
rules {
200202
# Rule: HTTP requests with unusual HTTP headers or URI path (signature #16).
201-
id = "60a48054bbcf4014ac63c44f1712a123"
203+
id = "60a48054bbcf4014ac63c44f1712a123"
202204
sensitivity_level = "default"
203-
action = "log"
205+
action = "log"
204206
}
205207
}
206208
}
207-
expression = "true"
208-
enabled = true
209209
}
210210
}
211211
```

src/content/docs/terraform/additional-configurations/rate-limiting-rules.mdx

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ sidebar:
66
head:
77
- tag: title
88
content: Configure rate limiting rules with Terraform
9-
109
---
1110

12-
import { Details, Render } from "~/components"
11+
import { Details, Render } from "~/components";
1312

1413
This page provides an example of creating a rate limiting rule in a zone using Terraform.
1514

1615
For more information on rate limiting rules, refer to [Rate limiting rules](/waf/rate-limiting-rules/) in the Cloudflare WAF documentation.
1716

1817
:::note
1918

20-
For more information on configuring the previous version of rate limiting rules in Terraform, refer to the [`cloudflare_rate_limit` resource](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/rate_limit) in the Terraform documentation.
19+
For more information on configuring the previous version of rate limiting rules in Terraform, refer to the [`cloudflare_rate_limit` resource](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/rate_limit) in the Terraform documentation.
2120
:::
2221

2322
## Before you start
@@ -30,7 +29,7 @@ For more information on configuring the previous version of rate limiting rules
3029

3130
<Render file="import-delete-existing-rulesets" />
3231

33-
***
32+
---
3433

3534
## Create a rate limiting rule
3635

@@ -45,31 +44,29 @@ resource "cloudflare_ruleset" "zone_rl" {
4544
phase = "http_ratelimit"
4645
4746
rules {
48-
action = "block"
47+
ref = "rate_limit_api_requests_ip"
48+
description = "Rate limit API requests by IP"
49+
expression = "(http.request.uri.path matches \"^/api/\")"
50+
action = "block"
4951
ratelimit {
5052
characteristics = ["cf.colo.id", "ip.src"]
5153
period = 60
5254
requests_per_period = 100
5355
mitigation_timeout = 600
5456
}
55-
expression = "(http.request.uri.path matches \"^/api/\")"
56-
description = "My rate limiting rule"
57-
enabled = true
5857
}
5958
}
6059
```
6160

62-
<Render file="add-new-rule" params={{ one: "rate limiting rule" }} /> <br/>
63-
61+
<Render file="add-new-rule" params={{ one: "rate limiting rule" }} /> <br />
6462

6563
<Details header="Account-level example configuration">
6664

6765
:::note[Before you start]
6866

67+
- Account-level rate limiting configuration requires an Enterprise plan with a paid add-on.
6968

70-
* Account-level rate limiting configuration requires an Enterprise plan with a paid add-on.
71-
72-
* Custom rulesets deployed at the account level will only apply to incoming traffic of zones on an Enterprise plan. The expression of your `execute` rule must end with `and cf.zone.plan eq "ENT"`.
69+
- Custom rulesets deployed at the account level will only apply to incoming traffic of zones on an Enterprise plan. The expression of your `execute` rule must end with `and cf.zone.plan eq "ENT"`.
7370
:::
7471

7572
This example defines a [custom ruleset](/ruleset-engine/custom-rulesets/) with a single rate limiting rule in account with ID `<ACCOUNT_ID>` that blocks traffic for the `/api/` path exceeding the configured rate. The second `cloudflare_ruleset` resource defines an `execute` rule that deploys the custom ruleset for traffic addressed at `example.com`.
@@ -83,16 +80,16 @@ resource "cloudflare_ruleset" "account_rl" {
8380
phase = "http_ratelimit"
8481
8582
rules {
86-
action = "block"
83+
ref = "rate_limit_api_ip"
84+
description = "Rate limit API requests by IP"
85+
expression = "http.request.uri.path contains \"/api/\""
86+
action = "block"
8787
ratelimit {
88-
characteristics = ["cf.colo.id", "ip.src"]
89-
period = 60
88+
characteristics = ["cf.colo.id", "ip.src"]
89+
period = 60
9090
requests_per_period = 100
91-
mitigation_timeout = 600
91+
mitigation_timeout = 600
9292
}
93-
expression = "http.request.uri.path contains \"/api/\""
94-
description = "API rule"
95-
enabled = true
9693
}
9794
}
9895
@@ -108,26 +105,25 @@ resource "cloudflare_ruleset" "account_rl_entrypoint" {
108105
109106
rules {
110107
# Deploy the previously defined custom ruleset containing a rate limiting rule
111-
action = "execute"
108+
ref = "deploy_rate_limit_example_com"
109+
description = "Deploy custom ruleset with RL rule"
110+
expression = "cf.zone.name eq \"example.com\" and cf.zone.plan eq \"ENT\""
111+
action = "execute"
112112
action_parameters {
113113
id = cloudflare_ruleset.account_rl.id
114114
}
115-
expression = "cf.zone.name eq \"example.com\" and cf.zone.plan eq \"ENT\""
116-
description = "Deploy custom ruleset with RL rule"
117-
enabled = true
118115
}
119116
}
120117
```
121118

122-
123119
</Details>
124120

125121
## Create an advanced rate limiting rule
126122

127123
This example creates a rate limiting rule in zone with ID `<ZONE_ID>` with:
128124

129-
* A custom counting expression that includes a response field (`http.response.code`).
130-
* A custom JSON response for rate limited requests.
125+
- A custom counting expression that includes a response field (`http.response.code`).
126+
- A custom JSON response for rate limited requests.
131127

132128
```tf
133129
resource "cloudflare_ruleset" "zone_rl_custom_response" {
@@ -138,26 +134,26 @@ resource "cloudflare_ruleset" "zone_rl_custom_response" {
138134
phase = "http_ratelimit"
139135
140136
rules {
141-
action = "block"
137+
ref = "rate_limit_example_com_status_404"
138+
description = "Rate limit requests to www.example.com when exceeding the threshold of 404 responses on /status/"
139+
expression = "http.host eq \"www.example.com\" and (http.request.uri.path matches \"^/status/\")"
140+
action = "block"
142141
action_parameters {
143142
response {
144-
status_code = 429
145-
content = "{\"response\": \"block\"}"
143+
status_code = 429
144+
content = "{\"response\": \"block\"}"
146145
content_type = "application/json"
147146
}
148147
}
149148
ratelimit {
150-
characteristics = ["ip.src", "cf.colo.id"]
151-
period = 10
149+
characteristics = ["ip.src", "cf.colo.id"]
150+
period = 10
152151
requests_per_period = 5
153-
mitigation_timeout = 30
152+
mitigation_timeout = 30
154153
counting_expression = "(http.host eq \"www.example.com\") and (http.request.uri.path matches \"^/status/\") and (http.response.code eq 404)"
155154
}
156-
expression = "http.host eq \"www.example.com\" and (http.request.uri.path matches \"^/status/\")"
157-
description = "Rate limit requests to www.example.com when exceeding the threshold of 404 responses on /status/"
158-
enabled = true
159155
}
160156
}
161157
```
162158

163-
<Render file="add-new-rule" params={{ one: "rate limiting rule" }} /> <br/>
159+
<Render file="add-new-rule" params={{ one: "rate limiting rule" }} /> <br />

0 commit comments

Comments
 (0)