---
title: Snippets
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/terraform)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Snippets

#### resource cloudflare\_snippet

##### required Expand Collapse

snippet\_name: String

Identify the snippet.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20snippet_name>)

zone\_id: String

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

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20zone_id>)

<details>

<summary>

metadata: Attributes

Provide metadata about the snippet.

</summary>

main\_module: String

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

<a href="#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20metadata%20%3E%20(attribute)%20main_module">Link to this property</a>

</details>

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20metadata>)

##### computed Expand Collapse

id: String

Identify the snippet.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20id>)

created\_on: Time

Indicates when the snippet was created.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20created_on>)

modified\_on: Time

Indicates when the snippet was last modified.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20modified_on>)

### cloudflare\_snippet

Terraform

HTTPTypeScriptPythonGoTerraform

```
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.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20snippet_name>)

zone\_id: String

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

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20zone_id>)

##### computed Expand Collapse

id: String

Identify the snippet.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20id>)

created\_on: Time

Indicates when the snippet was created.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20created_on>)

modified\_on: Time

Indicates when the snippet was last modified.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20modified_on>)

### cloudflare\_snippet

Terraform

HTTPTypeScriptPythonGoTerraform

```
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.

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20zone_id>)

##### optional Expand Collapse

max\_items?: Int64

Max items to fetch, default: 1000

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20max_items>)

##### computed Expand Collapse

<details>

<summary>

result: List\[Attributes]

The items returned by the data source

</summary>

id: String

Identify the snippet.

<a href="#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20id">Link to this property</a>

created\_on: Time

Indicates when the snippet was created.

<a href="#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20created_on">Link to this property</a>

snippet\_name: String

Identify the snippet.

<a href="#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20snippet_name">Link to this property</a>

modified\_on: Time

Indicates when the snippet was last modified.

<a href="#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20modified_on">Link to this property</a>

</details>

[Link to this property](<#(resource)%20snippets%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result>)

### cloudflare\_snippets

Terraform

HTTPTypeScriptPythonGoTerraform

```
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.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20zone_id>)

<details>

<summary>

rules: List\[Attributes]

Lists snippet rules.

</summary>

id: String

Specify the unique ID of the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules%20%3E%20(attribute)%20id">Link to this property</a>

expression: String

Define the expression that determines which traffic matches the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules%20%3E%20(attribute)%20expression">Link to this property</a>

last\_updated: Time

Specify the timestamp of when the rule was last modified.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules%20%3E%20(attribute)%20last_updated">Link to this property</a>

snippet\_name: String

Identify the snippet.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules%20%3E%20(attribute)%20snippet_name">Link to this property</a>

description?: String

Provide an informative description of the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules%20%3E%20(attribute)%20description">Link to this property</a>

enabled?: Bool

Indicate whether to execute the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules%20%3E%20(attribute)%20enabled">Link to this property</a>

</details>

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20rules>)

##### computed Expand Collapse

id: String

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

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20id>)

description: String

Provide an informative description of the rule.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20description>)

enabled: Bool

Indicate whether to execute the rule.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20enabled>)

expression: String

Define the expression that determines which traffic matches the rule.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20expression>)

last\_updated: Time

Specify the timestamp of when the rule was last modified.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20last_updated>)

snippet\_name: String

Identify the snippet.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20resource)%20%3E%20(attribute)%20snippet_name>)

### cloudflare\_snippet\_rules

Terraform

HTTPTypeScriptPythonGoTerraform

```
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
  }]
}
```

#### data cloudflare\_snippet\_rules

##### required Expand Collapse

zone\_id: String

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

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20zone_id>)

##### computed Expand Collapse

id: String

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

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20id>)

description: String

Provide an informative description of the rule.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20description>)

enabled: Bool

Indicate whether to execute the rule.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20enabled>)

expression: String

Define the expression that determines which traffic matches the rule.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20expression>)

last\_updated: Time

Specify the timestamp of when the rule was last modified.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20last_updated>)

snippet\_name: String

Identify the snippet.

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-single)%20%3E%20(attribute)%20snippet_name>)

### cloudflare\_snippet\_rules

Terraform

HTTPTypeScriptPythonGoTerraform

```
data "cloudflare_snippet_rules" "example_snippet_rules" {
  zone_id = "9f1839b6152d298aca64c4e906b6d074"
}
```

#### data cloudflare\_snippet\_rules\_list

##### required Expand Collapse

zone\_id: String

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

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20zone_id>)

##### optional Expand Collapse

max\_items?: Int64

Max items to fetch, default: 1000

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20max_items>)

##### computed Expand Collapse

<details>

<summary>

result: List\[Attributes]

The items returned by the data source

</summary>

id: String

Specify the unique ID of the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20id">Link to this property</a>

expression: String

Define the expression that determines which traffic matches the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20expression">Link to this property</a>

last\_updated: Time

Specify the timestamp of when the rule was last modified.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20last_updated">Link to this property</a>

snippet\_name: String

Identify the snippet.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20snippet_name">Link to this property</a>

description: String

Provide an informative description of the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20description">Link to this property</a>

enabled: Bool

Indicate whether to execute the rule.

<a href="#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result%20%3E%20(attribute)%20enabled">Link to this property</a>

</details>

[Link to this property](<#(resource)%20snippets.rules%20%3E%20(terraform%20datasource-plural)%20%3E%20(attribute)%20result>)

### cloudflare\_snippet\_rules\_list

Terraform

HTTPTypeScriptPythonGoTerraform

```
data "cloudflare_snippet_rules_list" "example_snippet_rules_list" {
  zone_id = "9f1839b6152d298aca64c4e906b6d074"
}
```