-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rules] Terraform support for Snippets (#18679)
- Loading branch information
1 parent
dcfaf8c
commit acf6ab7
Showing
6 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "<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 = "<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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters