Skip to content

Commit a4e0688

Browse files
dcpenakodster28
authored andcommitted
[Terraform] Added note about V4 code snippets (#19497)
* Added note about V4 code snippets * Created partial for note * Added note to additional pages * Added notes above each additional terraform example
1 parent ab828de commit a4e0688

14 files changed

+84
-0
lines changed

src/content/docs/terraform/additional-configurations/ddos-managed-rulesets.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ For more information on DDoS managed rulesets, refer to [Managed rulesets](/ddos
3636

3737
This example configures the [HTTP DDoS Attack Protection](/ddos-protection/managed-rulesets/http/) managed ruleset for a zone using Terraform, changing the sensitivity level of rule with ID fdfdac75430c4c47a959592f0aa5e68a to `low`.
3838

39+
<Render file="v4-code-snippets" />
40+
3941
```tf
4042
resource "cloudflare_ruleset" "zone_level_http_ddos_config" {
4143
zone_id = "<ZONE_ID>"
@@ -77,6 +79,8 @@ This example configures the [Network-layer DDoS Attack Protection](/ddos-protect
7779

7880
:::
7981

82+
<Render file="v4-code-snippets" />
83+
8084
```tf
8185
resource "cloudflare_ruleset" "account_level_network_ddos_config" {
8286
account_id = "<ACCOUNT_ID>"
@@ -126,6 +130,8 @@ The order of the rules is important: the rule with the highest sensitivity level
126130

127131
:::
128132

133+
<Render file="v4-code-snippets" />
134+
129135
```tf
130136
variable "zone_id" {
131137
default = "<ZONE_ID>"

src/content/docs/terraform/additional-configurations/rate-limiting-rules.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ For more information on configuring the previous version of rate limiting rules
3535

3636
This example creates a rate limiting rule in zone with ID `<ZONE_ID>` blocking traffic that exceeds the configured rate:
3737

38+
<Render file="v4-code-snippets" />
39+
3840
```tf
3941
resource "cloudflare_ruleset" "zone_rl" {
4042
zone_id = "<ZONE_ID>"
@@ -71,6 +73,8 @@ resource "cloudflare_ruleset" "zone_rl" {
7173

7274
This example defines a [custom ruleset](/ruleset-engine/custom-rulesets/) with a single rate limiting rule in account with ID `<ACCOUNT_ID>` that blocks traffic for the `/api/` path exceeding the configured rate. The second `cloudflare_ruleset` resource defines an `execute` rule that deploys the custom ruleset for traffic addressed at `example.com`.
7375

76+
<Render file="v4-code-snippets" />
77+
7478
```tf
7579
resource "cloudflare_ruleset" "account_rl" {
7680
account_id = <ACCOUNT_ID>
@@ -125,6 +129,8 @@ This example creates a rate limiting rule in zone with ID `<ZONE_ID>` with:
125129
- A custom counting expression that includes a response field (`http.response.code`).
126130
- A custom JSON response for rate limited requests.
127131

132+
<Render file="v4-code-snippets" />
133+
128134
```tf
129135
resource "cloudflare_ruleset" "zone_rl_custom_response" {
130136
zone_id = "<ZONE_ID>"

src/content/docs/terraform/additional-configurations/transform-rules.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ For more information on Transform Rules, refer to [Transform Rules](/rules/trans
3333

3434
The following example creates a Rewrite URL Rule that rewrites requests for `example.com/old-folder` to `example.com/new-folder`:
3535

36+
<Render file="v4-code-snippets" />
37+
3638
```tf
3739
resource "cloudflare_ruleset" "transform_url_rewrite" {
3840
zone_id = "<ZONE_ID>"
@@ -69,6 +71,8 @@ The following configuration example performs the following adjustments to HTTP r
6971
- Adds a `my-header-2` header to the request with a dynamic value defined by an expression.
7072
- Deletes the `existing-header` header from the request, if it exists.
7173

74+
<Render file="v4-code-snippets" />
75+
7276
```tf
7377
resource "cloudflare_ruleset" "transform_modify_request_headers" {
7478
zone_id = "<ZONE_ID>"
@@ -117,6 +121,8 @@ The following configuration example performs the following adjustments to HTTP r
117121
- Adds a `my-header-2` header to the response with a dynamic value defined by an expression.
118122
- Deletes the `existing-header` header from the response, if it exists.
119123

124+
<Render file="v4-code-snippets" />
125+
120126
```tf
121127
resource "cloudflare_ruleset" "transform_modify_response_headers" {
122128
zone_id = "<ZONE_ID>"

src/content/docs/terraform/additional-configurations/waf-custom-rules.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ For more information on custom rules, refer to [Custom rules](/waf/custom-rules/
4040

4141
The following example configures a custom rule in the zone entry point ruleset for the `http_request_firewall_custom` phase for zone with ID `<ZONE_ID>`. The rule will block all traffic on non-standard HTTP(S) ports:
4242

43+
<Render file="v4-code-snippets" />
44+
4345
```tf
4446
resource "cloudflare_ruleset" "zone_custom_firewall" {
4547
zone_id = "<ZONE_ID>"
@@ -67,6 +69,8 @@ For more information on enabling leaked credentials detection using Terraform, r
6769

6870
This example adds a custom rule that challenges requests with leaked credentials by using one of the [leaked credentials fields](/waf/detections/leaked-credentials/#leaked-credentials-fields) in the rule expression.
6971

72+
<Render file="v4-code-snippets" />
73+
7074
```tf
7175
resource "cloudflare_ruleset" "zone_custom_firewall_leaked_creds" {
7276
zone_id = "<ZONE_ID>"
@@ -94,6 +98,8 @@ For more information on enabling malicious uploads detection using Terraform, re
9498

9599
This example adds a custom rule that blocks requests with one or more <GlossaryTooltip term="content object">content objects</GlossaryTooltip> considered malicious by using one of the [content scanning fields](/waf/detections/malicious-uploads/#content-scanning-fields) in the rule expression.
96100

101+
<Render file="v4-code-snippets" />
102+
97103
```tf
98104
resource "cloudflare_ruleset" "zone_custom_firewall_malicious_uploads" {
99105
zone_id = "<ZONE_ID>"
@@ -125,6 +131,8 @@ You can only create and deploy custom rulesets at the account level.
125131

126132
The following configuration creates the custom ruleset with a single rule:
127133

134+
<Render file="v4-code-snippets" />
135+
128136
```tf
129137
resource "cloudflare_ruleset" "account_firewall_custom_ruleset" {
130138
account_id = "<ACCOUNT_ID>"
@@ -149,6 +157,8 @@ resource "cloudflare_ruleset" "account_firewall_custom_ruleset" {
149157

150158
The following configuration deploys the custom ruleset at the account level. It defines a dependency on the `account_firewall_custom_ruleset` resource and uses the ID of the created custom ruleset in `action_parameters`:
151159

160+
<Render file="v4-code-snippets" />
161+
152162
```tf
153163
resource "cloudflare_ruleset" "account_firewall_custom_entrypoint" {
154164
account_id = "<ACCOUNT_ID>"
@@ -181,6 +191,8 @@ The following configuration creates a custom ruleset with a single rule that [ch
181191

182192
You can only add exposed credential checks to rules in a custom ruleset (that is, a ruleset with `kind = "custom"`).
183193

194+
<Render file="v4-code-snippets" />
195+
184196
```tf
185197
resource "cloudflare_ruleset" "account_firewall_custom_ruleset_exposed_creds" {
186198
account_id = "<ACCOUNT_ID>"
@@ -213,6 +225,8 @@ resource "cloudflare_ruleset" "account_firewall_custom_ruleset_exposed_creds" {
213225

214226
The following configuration deploys the custom ruleset. It defines a dependency on the `account_firewall_custom_ruleset_exposed_creds` resource and obtains the ID of the created custom ruleset:
215227

228+
<Render file="v4-code-snippets" />
229+
216230
```tf
217231
resource "cloudflare_ruleset" "account_firewall_custom_entrypoint" {
218232
account_id = "<ACCOUNT_ID>"

src/content/docs/terraform/additional-configurations/waf-managed-rulesets.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ For more information on WAF Managed Rules, refer to [WAF Managed Rules](/waf/man
3636

3737
The following example deploys two managed rulesets to the zone with ID `<ZONE_ID>` using Terraform, using a `cloudflare_ruleset` resource with two rules that execute the managed rulesets.
3838

39+
<Render file="v4-code-snippets" />
40+
3941
```tf
4042
# Configure a ruleset at the zone level for the "http_request_firewall_managed" phase
4143
resource "cloudflare_ruleset" "zone_level_managed_waf" {
@@ -80,6 +82,8 @@ resource "cloudflare_ruleset" "zone_level_managed_waf" {
8082

8183
The following example deploys two managed rulesets to the account with ID `<ACCOUNT_ID>` using Terraform, using a `cloudflare_ruleset` resource with two rules that execute the managed rulesets for two hostnames belonging to Enterprise zones.
8284

85+
<Render file="v4-code-snippets" />
86+
8387
```tf
8488
resource "cloudflare_ruleset" "account_level_managed_waf" {
8589
account_id = "<ACCOUNT_ID>"
@@ -123,6 +127,8 @@ The following example adds two [skip rules](/waf/managed-rules/waf-exceptions/)
123127

124128
Add the two skip rules to the `cloudflare_ruleset` resource before the rule that deploys the Cloudflare Managed Ruleset:
125129

130+
<Render file="v4-code-snippets" />
131+
126132
```tf null {4-13,15-27}
127133
resource "cloudflare_ruleset" "zone_level_managed_waf" {
128134
# (...)
@@ -184,6 +190,8 @@ The following example adds three [overrides](/ruleset-engine/managed-rulesets/ov
184190

185191
The following configuration includes the three overrides in the rule that executes the Cloudflare Managed Ruleset:
186192

193+
<Render file="v4-code-snippets" />
194+
187195
```tf null {9-24}
188196
# (...)
189197
@@ -223,6 +231,8 @@ This example enables [payload logging](/waf/managed-rules/payload-logging/) for
223231

224232
Building upon the rule that deploys the Cloudflare Managed Ruleset, the following rule configuration adds the `matched_data` object with the public key used to encrypt the payload:
225233

234+
<Render file="v4-code-snippets" />
235+
226236
```tf null {9-11}
227237
# (...)
228238
@@ -262,6 +272,8 @@ The following example rule of a `cloudflare_ruleset` Terraform resource performs
262272
- Sets the score threshold to `60` (_Low_).
263273
- Sets the ruleset action to `log`.
264274

275+
<Render file="v4-code-snippets" />
276+
265277
```tf null {8-25}
266278
# (...)
267279

src/content/docs/terraform/advanced-topics/import-cloudflare-resources.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pcx_content_type: tutorial
33
title: Import Cloudflare resources
44
---
55

6+
import { Render } from "~/components";
7+
68
An important point to understand about Terraform is that it can only manage configuration it created or was explicitly told about after the fact. The reason for this limitation is that Terraform expects to be authoritative for the resources it manages. It relies on two types of files to understand what resources it controls and what state they are in. Terraform determines when and how to make changes from the following:
79

810
- A [configuration file](https://developer.hashicorp.com/terraform/language) (ending in `.tf`) that defines the configuration of resources for Terraform to manage. This is what you worked with in the tutorial steps.
@@ -54,6 +56,8 @@ To start managing existing Cloudflare resources in Terraform, for example, DNS r
5456

5557
If you do not have a Terraform configuration file defined, you need the `provider` block defined as follows:
5658

59+
<Render file="v4-code-snippets" />
60+
5761
```hcl
5862
provider 'cloudflare' {
5963
# Cloudflare email saved in $CLOUDFLARE_EMAIL
@@ -71,6 +75,8 @@ cf-terraforming generate --email $CLOUDFLARE_EMAIL --token $CLOUDFLARE_API_TOKEN
7175

7276
If you had not redirected the output to the `importing-example.tf` file, the result displayed in the standard output (your terminal window) would look like the following:
7377

78+
<Render file="v4-code-snippets" />
79+
7480
```tf
7581
resource "cloudflare_record" "terraform_managed_resource_3c0b456bc2aa443089c5f40f45f51b31" {
7682
name = "@"

src/content/docs/terraform/advanced-topics/remote-backend.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ After your token has been successfully created, review your **Secret Access Key*
3838

3939
Update your [`cloudflare.tf`](/terraform/tutorial/initialize-terraform/) file to include a [backend](https://developer.hashicorp.com/terraform/language/settings/backends/configuration) for the `<YOUR_BUCKET_NAME>` bucket you created above.
4040

41+
<Render file="v4-code-snippets" />
42+
4143
```tf
4244
terraform {
4345
backend "s3" {

src/content/docs/terraform/tutorial/add-page-rules.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ head:
88
content: Add exceptions with Page Rules
99
---
1010

11+
import { Render } from "~/components";
12+
1113
In the [Configure HTTPS settings](/terraform/tutorial/configure-https-settings/) tutorial, you configured zone settings that apply to all incoming requests for `example.com`. In this tutorial, you will add an exception to these settings using [Page Rules](/rules/page-rules/).
1214

1315
Specifically, you will increase the security level for a URL known to be expensive to render and cannot be cached: `https://www.example.com/expensive-db-call`. Additionally, you will add a redirect from the previous URL used to host this page.
1416

17+
<Render file="v4-code-snippets" />
18+
1519
## 1. Create a new branch and append the page rule
1620

1721
Create a new branch and append the configuration.

src/content/docs/terraform/tutorial/configure-https-settings.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ head:
88
content: Configure HTTPS settings
99
---
1010

11+
import { Render } from "~/components";
12+
1113
After proxying a basic website through Cloudflare, you can use Terraform to adjust zone settings. In this tutorial, you will configure some optional HTTPS settings and then push the updated configuration to GitHub for posterity.
1214

1315
You will use a new Git branch for the changes and then merge it into the `master` branch before applying. On a team, you might consider using this step as an opportunity for others to review your change before merging and deploying it. You can also integrate Terraform into your CI/CD system to perform tests automatically using another Cloudflare domain.
1416

17+
<Render file="v4-code-snippets" />
18+
1519
## 1. Create a new branch and append the new zone settings
1620

1721
In this step, modify the Terraform configuration to enable the following settings:

src/content/docs/terraform/tutorial/initialize-terraform.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ head:
88
content: Introduction to Terraform init
99
---
1010

11+
import { Render } from "~/components";
12+
1113
This tutorial shows you how to get started with Terraform. The tutorial uses an example scenario where you have a web server for your domain, accessible on `203.0.113.10`, and you just signed up your domain (`example.com`) on Cloudflare to manage everything in Terraform.
1214

1315
Before you begin, ensure you have [installed Terraform](/terraform/installing/). You will also need to [create an API Token](/fundamentals/api/get-started/create-token/) with permissions to edit resources for this tutorial.
1416

17+
<Render file="v4-code-snippets" />
18+
1519
## 1. Define your first Terraform config file
1620

1721
Create an initial Terraform config file, filling in your own values for the [API token](/fundamentals/api/get-started/create-token/), [zone ID](/fundamentals/setup/find-account-and-zone-ids/), [account ID](/fundamentals/setup/find-account-and-zone-ids/), and [domain](/fundamentals/setup/manage-domains/add-site/).

0 commit comments

Comments
 (0)