diff --git a/src/content/changelogs/rules.yaml b/src/content/changelogs/rules.yaml index 76581f6a0281998..a6178be83a95096 100644 --- a/src/content/changelogs/rules.yaml +++ b/src/content/changelogs/rules.yaml @@ -5,6 +5,10 @@ productLink: "/rules/" productArea: Application performance productAreaLink: /fundamentals/reference/changelog/performance/ entries: + - publish_date: "2024-12-11" + title: Snippets support in the Cloudflare provider for Terraform + description: |- + You can now manage Snippets using Terraform. For more information, refer to [Configure Snippets using Terraform](/rules/snippets/create-terraform/). - publish_date: "2024-11-22" title: Support for Cloudflare R2 object storage in Cloud Connector description: |- diff --git a/src/content/docs/rules/snippets/create-api.mdx b/src/content/docs/rules/snippets/create-api.mdx index af5f93bae585ccb..ea776b1f1d2134b 100644 --- a/src/content/docs/rules/snippets/create-api.mdx +++ b/src/content/docs/rules/snippets/create-api.mdx @@ -1,8 +1,9 @@ --- -title: Configure via API +title: Configure Snippets via API pcx_content_type: how-to sidebar: order: 3 + label: Configure via API head: - tag: title content: Configure Snippets via API diff --git a/src/content/docs/rules/snippets/create-dashboard.mdx b/src/content/docs/rules/snippets/create-dashboard.mdx index c49892d54199eb5..759f9c5c33736d3 100644 --- a/src/content/docs/rules/snippets/create-dashboard.mdx +++ b/src/content/docs/rules/snippets/create-dashboard.mdx @@ -1,12 +1,12 @@ --- -title: Create in the dashboard +title: Create a snippet in the dashboard pcx_content_type: how-to sidebar: order: 2 + label: Create in the dashboard head: - tag: title content: Create a snippet in the dashboard - --- The snippet creation wizard will guide you through the following steps: diff --git a/src/content/docs/rules/snippets/create-terraform.mdx b/src/content/docs/rules/snippets/create-terraform.mdx new file mode 100644 index 000000000000000..4212398ef282fc0 --- /dev/null +++ b/src/content/docs/rules/snippets/create-terraform.mdx @@ -0,0 +1,49 @@ +--- +title: Configure Snippets using Terraform +pcx_content_type: how-to +sidebar: + order: 4 + label: Configure using Terraform +head: + - tag: title + content: Configure Snippets using Terraform +--- + +You can create Snippets using the [Terraform Cloudflare provider](https://registry.terraform.io/providers/cloudflare/cloudflare/latest). + +To get started with Terraform for Cloudflare configuration, refer to [Terraform: Get started](/terraform/installing/). + +## Example configuration + +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. + +```tf +resource "cloudflare_snippet" "my_snippet" { + zone_id = "" + name = "my_test_snippet_1" + main_module = "file1.js" + files { + name = "file1.js" + content = file("file1.js") + } +} + +resource "cloudflare_snippet_rules" "cookie_snippet_rule" { + zone_id = "" + rules { + enabled = true + expression = "http.cookie eq \"a=b\"" + description = "Trigger snippet on specific cookie" + snippet_name = "my_test_snippet_1" + } + depends_on = ["cloudflare_snippet.my_snippet"] +} +``` + +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. + +All `snippet_name` values in the `cloudflare_snippet_rules` resource must match the names of existing snippets. + +## More resources + +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. diff --git a/src/content/docs/rules/snippets/errors.mdx b/src/content/docs/rules/snippets/errors.mdx index 82ceaba555f5af8..7399b203d540ffe 100644 --- a/src/content/docs/rules/snippets/errors.mdx +++ b/src/content/docs/rules/snippets/errors.mdx @@ -2,14 +2,13 @@ title: Common errors pcx_content_type: troubleshooting sidebar: - order: 4 + order: 8 head: - tag: title content: Common errors - --- -import { GlossaryTooltip } from "~/components" +import { GlossaryTooltip } from "~/components"; Cloudflare Snippets may encounter specific errors during execution. Here are the common errors: diff --git a/src/content/docs/rules/snippets/examples/index.mdx b/src/content/docs/rules/snippets/examples/index.mdx index 8a4522691d2c8b0..568018e12cd88b1 100644 --- a/src/content/docs/rules/snippets/examples/index.mdx +++ b/src/content/docs/rules/snippets/examples/index.mdx @@ -4,7 +4,7 @@ hideChildren: true pcx_content_type: navigation title: Examples sidebar: - order: 3 + order: 7 --- import { ListExamples } from "~/components";