Skip to content
Start here

Snippets

resource cloudflare_snippet

required Expand Collapse
snippet_name: String

Identify the snippet.

zone_id: String

Use this field to specify the unique ID of the zone.

metadata: Attributes

Provide metadata about the snippet.

main_module: String

Specify the name of the file that contains the main module of the snippet.

computed Expand Collapse
created_on: Time

Indicates when the snippet was created.

modified_on: Time

Indicates when the snippet was last modified.

cloudflare_snippet

resource "cloudflare_snippet" "example_snippet" {
  zone_id = "9f1839b6152d298aca64c4e906b6d074"
  snippet_name = "my_snippet"
  metadata = {
    main_module = "main.js"
  }
}

data cloudflare_snippet

required Expand Collapse
snippet_name: String

Identify the snippet.

zone_id: String

Use this field to specify the unique ID of the zone.

computed Expand Collapse
created_on: Time

Indicates when the snippet was created.

modified_on: Time

Indicates when the snippet was last modified.

cloudflare_snippet

data "cloudflare_snippet" "example_snippet" {
  zone_id = "9f1839b6152d298aca64c4e906b6d074"
  snippet_name = "my_snippet"
}

data cloudflare_snippets

required Expand Collapse
zone_id: String

Use this field to specify the unique ID of the zone.

optional Expand Collapse
max_items?: Int64

Max items to fetch, default: 1000

computed Expand Collapse
result: List[Attributes]

The items returned by the data source

created_on: Time

Indicates when the snippet was created.

snippet_name: String

Identify the snippet.

modified_on: Time

Indicates when the snippet was last modified.

cloudflare_snippets

data "cloudflare_snippets" "example_snippets" {
  zone_id = "9f1839b6152d298aca64c4e906b6d074"
}

SnippetsRules

resource cloudflare_snippet_rules

required Expand Collapse
zone_id: String

Use this field to specify the unique ID of the zone.

rules: List[Attributes]

Lists snippet rules.

id: String

Specify the unique ID of the rule.

expression: String

Define the expression that determines which traffic matches the rule.

last_updated: Time

Specify the timestamp of when the rule was last modified.

snippet_name: String

Identify the snippet.

description?: String

Provide an informative description of the rule.

enabled?: Bool

Indicate whether to execute the rule.

cloudflare_snippet_rules

resource "cloudflare_snippet_rules" "example_snippet_rules" {
  zone_id = "9f1839b6152d298aca64c4e906b6d074"
  rules = [{
    expression = "ip.src eq 1.1.1.1"
    snippet_name = "my_snippet"
    description = "Execute my_snippet when IP address is 1.1.1.1."
    enabled = true
  }]
}