Skip to content

Commit acf6ab7

Browse files
authored
[Rules] Terraform support for Snippets (#18679)
1 parent dcfaf8c commit acf6ab7

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

src/content/changelogs/rules.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ productLink: "/rules/"
55
productArea: Application performance
66
productAreaLink: /fundamentals/reference/changelog/performance/
77
entries:
8+
- publish_date: "2024-12-11"
9+
title: Snippets support in the Cloudflare provider for Terraform
10+
description: |-
11+
You can now manage Snippets using Terraform. For more information, refer to [Configure Snippets using Terraform](/rules/snippets/create-terraform/).
812
- publish_date: "2024-11-22"
913
title: Support for Cloudflare R2 object storage in Cloud Connector
1014
description: |-

src/content/docs/rules/snippets/create-api.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
2-
title: Configure via API
2+
title: Configure Snippets via API
33
pcx_content_type: how-to
44
sidebar:
55
order: 3
6+
label: Configure via API
67
head:
78
- tag: title
89
content: Configure Snippets via API

src/content/docs/rules/snippets/create-dashboard.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Create in the dashboard
2+
title: Create a snippet in the dashboard
33
pcx_content_type: how-to
44
sidebar:
55
order: 2
6+
label: Create in the dashboard
67
head:
78
- tag: title
89
content: Create a snippet in the dashboard
9-
1010
---
1111

1212
The snippet creation wizard will guide you through the following steps:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Configure Snippets using Terraform
3+
pcx_content_type: how-to
4+
sidebar:
5+
order: 4
6+
label: Configure using Terraform
7+
head:
8+
- tag: title
9+
content: Configure Snippets using Terraform
10+
---
11+
12+
You can create Snippets using the [Terraform Cloudflare provider](https://registry.terraform.io/providers/cloudflare/cloudflare/latest).
13+
14+
To get started with Terraform for Cloudflare configuration, refer to [Terraform: Get started](/terraform/installing/).
15+
16+
## Example configuration
17+
18+
The following example Terraform configuration creates a snippet and an associated snippet rule that defines when the snippet code will run. The snippet code is loaded from the `file1.js` file in your machine.
19+
20+
```tf
21+
resource "cloudflare_snippet" "my_snippet" {
22+
zone_id = "<ZONE_ID>"
23+
name = "my_test_snippet_1"
24+
main_module = "file1.js"
25+
files {
26+
name = "file1.js"
27+
content = file("file1.js")
28+
}
29+
}
30+
31+
resource "cloudflare_snippet_rules" "cookie_snippet_rule" {
32+
zone_id = "<ZONE_ID>"
33+
rules {
34+
enabled = true
35+
expression = "http.cookie eq \"a=b\""
36+
description = "Trigger snippet on specific cookie"
37+
snippet_name = "my_test_snippet_1"
38+
}
39+
depends_on = ["cloudflare_snippet.my_snippet"]
40+
}
41+
```
42+
43+
The name of a snippet can only contain the characters `a-z`, `0-9`, and `_` (underscore). The name must be unique in the context of the zone.
44+
45+
All `snippet_name` values in the `cloudflare_snippet_rules` resource must match the names of existing snippets.
46+
47+
## More resources
48+
49+
Refer to the [Terraform Cloudflare provider documentation](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs) for more information on the `cloudflare_snippet` and `cloudflare_snippet_rules` resources.

src/content/docs/rules/snippets/errors.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
title: Common errors
33
pcx_content_type: troubleshooting
44
sidebar:
5-
order: 4
5+
order: 8
66
head:
77
- tag: title
88
content: Common errors
9-
109
---
1110

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

1413
Cloudflare Snippets may encounter specific errors during execution. Here are the common errors:
1514

src/content/docs/rules/snippets/examples/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ hideChildren: true
44
pcx_content_type: navigation
55
title: Examples
66
sidebar:
7-
order: 3
7+
order: 7
88
---
99

1010
import { ListExamples } from "~/components";

0 commit comments

Comments
 (0)