Skip to content

Commit f04aae9

Browse files
authored
[Terraform] Fix rule ID changes (#18630)
1 parent 8103a82 commit f04aae9

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/content/docs/terraform/additional-configurations/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ title: Additional configurations
33
pcx_content_type: navigation
44
sidebar:
55
order: 4
6-
6+
group:
7+
hideIndex: true
78
---
89

9-
import { DirectoryListing } from "~/components"
10+
import { DirectoryListing } from "~/components";
1011

1112
<DirectoryListing />

src/content/docs/terraform/advanced-topics/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ pcx_content_type: navigation
33
title: Advanced topics
44
sidebar:
55
order: 5
6-
6+
group:
7+
hideIndex: true
78
---
89

9-
import { DirectoryListing } from "~/components"
10+
import { DirectoryListing } from "~/components";
1011

1112
<DirectoryListing />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
pcx_content_type: navigation
3+
title: Troubleshooting
4+
sidebar:
5+
order: 6
6+
group:
7+
hideIndex: true
8+
---
9+
10+
import { DirectoryListing } from "~/components";
11+
12+
The following pages are useful for troubleshooting Terraform issues.
13+
14+
<DirectoryListing />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
pcx_content_type: troubleshooting
3+
title: The rule ID changes when I modify a rule
4+
sidebar:
5+
label: Rule ID changes
6+
---
7+
8+
For [`cloudflare_ruleset`](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/ruleset) resources, the Cloudflare provider may delete a rule and create a new one when you modify a ruleset rule in your Terraform configuration. This happens when the provider cannot match your new rule configuration in Terraform with an existing rule in your Cloudflare configuration. In this situation, modifying a rule in your Terraform configuration and applying the changes will create a new rule with a different rule ID in your Cloudflare account or zone.
9+
10+
This behavior may have an impact on any automation or monitoring systems you may have configured that rely on having immutable rule IDs between rule modifications.
11+
12+
## How to keep the same rule ID between modifications
13+
14+
To keep the existing rule ID when making changes to a rule through Terraform, add a `ref` field to the rule.
15+
16+
The `ref` field is a user-defined external identifier that must be unique for each rule in a ruleset. When you provide a `ref` value, the provider will match the rule in your updated Terraform configuration with the existing rule with the same `ref` external identifier, and the rule ID will be preserved.
17+
18+
`ref` values have a string data type with a minimum length of one character. For example, `my_ref`.
19+
20+
## `cf-terraforming` support for `ref` field values
21+
22+
By default, when you create a rule, its `ref` value will be equal to the rule ID. You can set or modify `ref` values via Cloudflare API.
23+
24+
When you [import your existing Cloudflare configuration to Terraform](/terraform/advanced-topics/import-cloudflare-resources/) using [`cf-terraforming`](https://github.com/cloudflare/cf-terraforming), the generated Terraform configuration will have `ref` values for each rule, with the same value as the rule ID.
25+
26+
If you manually created your Terraform configuration and your rules' configuration does not have a `ref` field, add a `ref` field to each rule so that each rule modification does not generate a new rule ID.

0 commit comments

Comments
 (0)