Skip to content

Commit d9a4925

Browse files
authored
APIOPS-11336: Update revert-configuration.mdx (#25203)
* Update revert-configuration.mdx * APIOPS-11336: Update revert-configuration.mdx * Update revert-configuration.mdx * Update revert-configuration.mdx
1 parent c58b49e commit d9a4925

File tree

1 file changed

+43
-248
lines changed

1 file changed

+43
-248
lines changed

src/content/docs/terraform/tutorial/revert-configuration.mdx

Lines changed: 43 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -14,301 +14,96 @@ Sometimes, you may have to roll back configuration changes. For example, you mig
1414

1515
To revert your configuration, check out the desired branch and ask Terraform to move your Cloudflare settings back in time. If you accidentally brought your site down, consider establishing a good strategy for peer reviewing pull requests rather than merging directly to `master` as done in the tutorials for brevity.
1616

17-
<Render file="v4-code-snippets" product="terraform" />
18-
17+
<Render file="v5-code-snippets" product="terraform" />
1918
## 1. Review your configuration history
2019

21-
Before determining how far back to revert, review the versioned history:
20+
Before determining how far back to revert, review your Git history:
2221

2322
```sh
24-
git log
23+
git log --oneline
2524
```
2625

2726
```sh output
28-
commit d4fec164581bec44684a4d59bb80aec1f1da5a6e
29-
Author: Me
30-
Date: Wed Apr 18 22:04:52 2018 -0700
31-
32-
Step 5 - Add two Page Rules.
33-
34-
commit bc9aa9a465a4c8d6deeaa0491814c9f364e9aa8a
35-
Author: Me
36-
Date: Sun Apr 15 23:58:35 2018 -0700
37-
38-
Step 4 - Create load balancer (LB) monitor, LB pool, and LB.
39-
40-
commit 6761a4f754e77322629ba4e90a90a3defa1fd4b6
41-
Author: Me
42-
Date: Wed Apr 11 11:20:25 2018 -0700
43-
44-
Step 4 - Add additional 'www' DNS record for Asia data center.
45-
46-
commit d540600b942cbd89d03db52211698d331f7bd6d7
47-
Author: Me
48-
Date: Sun Apr 8 22:21:27 2018 -0700
49-
50-
Step 3 - Enable TLS 1.3, Always Use HTTPS, and SSL Strict mode.
51-
52-
commit 494c6d61b918fce337ca4c0725c9bbc01e00f0b7
53-
Author: Me
54-
Date: Sun Apr 8 19:58:56 2018 -0700
55-
56-
Step 2 - Ignore terraform plugin directory and state file.
57-
58-
commit 5acea176050463418f6ac1029674c152e3056bc6
59-
Author: Me
60-
Date: Sun Apr 8 19:52:13 2018 -0700
61-
62-
Step 1 - Initial commit with webserver definition.
27+
f1a2b3c Step 5 - Add two Page Rules
28+
d4e5f6g Step 4 - Create load balancer (LB) monitor, LB pool, and LB
29+
a7b8c9d Step 3 - Enable TLS 1.3, automatic HTTPS rewrites, and strict SSL
30+
e1f2g3h Step 2 - Initial Terraform v5 configuration
6331
```
6432

6533
Another benefit of storing your Cloudflare configuration in Git is that you can see who made the change. You can also see who reviewed and approved the change if you peer-review pull requests.
66-
67-
## 2. Examining specific historical changes
68-
69-
Check when the last change was made:
70-
7134
```sh
72-
git show
73-
```
74-
75-
```sh output
76-
commit d4fec164581bec44684a4d59bb80aec1f1da5a6e
77-
Author: Me
78-
Date: Wed Apr 18 22:04:52 2018 -0700
79-
80-
Step 5 - Add two Page Rules.
81-
82-
diff --git a/cloudflare.tf b/cloudflare.tf
83-
index 0b39450..ef11d8a 100644
84-
--- a/cloudflare.tf
85-
+++ b/cloudflare.tf
86-
@@ -94,3 +94,26 @@ resource "cloudflare_load_balancer" "www-lb" {
87-
description = "example load balancer"
88-
proxied = true
89-
}
90-
+
91-
+resource "cloudflare_page_rule" "increase-security-on-expensive-page" {
92-
+ zone_id = var.zone_id
93-
+ target = "www.${var.domain}/expensive-db-call"
94-
+ priority = 1
95-
+
96-
+ actions {
97-
+ security_level = "under_attack",
98-
+ }
99-
+}
100-
+
101-
+resource "cloudflare_page_rule" "redirect-to-new-db-page" {
102-
+ zone_id = var.zone_id
103-
+ target = "www.${var.domain}/old-location.php"
104-
+ priority = 2
105-
+
106-
+ actions {
107-
+ forwarding_url {
108-
+ url = "https://${var.domain}/expensive-db-call"
109-
+ status_code = 301
110-
+ }
111-
+ }
112-
+}
35+
git log
11336
```
114-
115-
Review the past few changes:
116-
37+
Check when the last change was made:
11738
```sh
118-
git log -p -3
119-
```
120-
121-
```sh output
122-
...
123-
// page rule config from above
124-
...
125-
126-
commit bc9aa9a465a4c8d6deeaa0491814c9f364e9aa8a
127-
Author: Me
128-
Date: Sun Apr 15 23:58:35 2018 -0700
129-
130-
Step 4 - Create load balancer (LB) monitor, LB pool, and LB.
131-
132-
diff --git a/cloudflare.tf b/cloudflare.tf
133-
index b92cb6f..195b646 100644
134-
--- a/cloudflare.tf
135-
+++ b/cloudflare.tf
136-
@@ -59,3 +59,38 @@ resource "cloudflare_record" "www-asia" {
137-
type = "A"
138-
proxied = true
139-
}
140-
+
141-
+resource "cloudflare_load_balancer_monitor" "get-root-https" {
142-
+ account_id = var.account_id
143-
+ expected_body = "alive"
144-
+ expected_codes = "200"
145-
+ method = "GET"
146-
+ timeout = 5
147-
+ path = "/"
148-
+ interval = 60
149-
+ retries = 2
150-
+ description = "GET / over HTTPS - expect 200"
151-
+}
152-
+
153-
+resource "cloudflare_load_balancer_pool" "www-servers" {
154-
+ account_id = var.account_id
155-
+ name = "www-servers"
156-
+ monitor = cloudflare_load_balancer_monitor.get-root-https.id
157-
+ origins {
158-
+ name = "www-us"
159-
+ address = "203.0.113.10"
160-
+ }
161-
+ origins {
162-
+ name = "www-asia"
163-
+ address = "198.51.100.15"
164-
+ }
165-
+ description = "www origins"
166-
+ enabled = true
167-
+ minimum_origins = 1
168-
+ notification_email = "[email protected]"
169-
+ check_regions = ["WNAM", "ENAM", "WEU", "EEU", "SEAS", "NEAS"]
170-
+}
171-
+resource "cloudflare_load_balancer" "www-lb" {
172-
+ zone_id = var.zone_id
173-
+ name = "www-lb"
174-
+ default_pool_ids = [cloudflare_load_balancer_pool.www-servers.id]
175-
+ fallback_pool_id = cloudflare_load_balancer_pool.www-servers.id
176-
+ description = "example load balancer"
177-
+ proxied = true
178-
+}
179-
180-
commit 6761a4f754e77322629ba4e90a90a3defa1fd4b6
181-
Author: Me
182-
Date: Wed Apr 11 11:20:25 2018 -0700
183-
184-
Step 4 - Add additional 'www' DNS record for Asia data center.
185-
186-
diff --git a/cloudflare.tf b/cloudflare.tf
187-
index 9f25a0c..b92cb6f 100644
188-
--- a/cloudflare.tf
189-
+++ b/cloudflare.tf
190-
@@ -52,3 +52,10 @@ resource "cloudflare_zone_settings_override" "example-com-settings" {
191-
ssl = "strict"
192-
}
193-
}
194-
+
195-
+resource "cloudflare_record" "www-asia" {
196-
+ zone_id = var.zone_id
197-
+ name = "www"
198-
+ value = "198.51.100.15"
199-
+ type = "A"
200-
+ proxied = true
201-
+}
39+
git show
20240
```
41+
This shows the most recent commit and what files changed.
20342

204-
## 3. Redeploy the previous configuration
43+
## 2. Scenario: Revert the Page Rules
20544

20645
Assume that shortly after you deployed the Page Rules when following the [Add exceptions with Page Rules](/terraform/tutorial/add-page-rules/) tutorial, you are told the URL is no longer needed, and the security setting and redirect should be dropped.
20746

20847
While you can always edit the config file directly and delete those entries, you can use Git to do that for you.
20948

210-
### i. Revert the branch to the previous commit
211-
212-
Run the following Git command to revert the last commit without rewriting history:
213-
214-
```sh
215-
git revert HEAD~1..HEAD
216-
```
217-
218-
```sh output
219-
[master f9a6f7d] Revert "Step 6 - Bug fix."
220-
1 file changed, 1 insertion(+), 1 deletion(-)
221-
```
49+
### Revert using Git
50+
Use Git to create a revert commit that undoes the Page Rules changes:
22251

22352
```sh
224-
git log -2
53+
git revert HEAD
22554
```
55+
Git will open your default editor with a commit message. Save and close to accept the default message, or customize it:
22656

22757
```sh output
228-
commit f9a6f7db72ea1437e146050a5e7556052ecc9a1a
229-
Author: Me
230-
Date: Wed Apr 18 23:28:09 2018 -0700
58+
Revert "Add Page Rules for security and redirects"
23159

232-
Revert "Step 5 - Add two Page Rules."
233-
234-
This reverts commit d4fec164581bec44684a4d59bb80aec1f1da5a6e.
235-
236-
commit d4fec164581bec44684a4d59bb80aec1f1da5a6e
237-
Author: Me
238-
Date: Wed Apr 18 22:04:52 2018 -0700
239-
240-
Step 5 - Add two Page Rules.
60+
This reverts commit f1a2b3c4d5e6f7a8b9c0d1e2f3g4h5i6j7k8l9m0.
24161
```
24262

243-
### ii. Preview the changes
63+
## 3. Preview the changes
24464

245-
Run `terraform plan` and check the execution plan:
65+
Check what Terraform will do with the reverted configuration:
24666

24767
```sh
24868
terraform plan
24969
```
250-
70+
Expected output:
25171
```sh output
252-
Refreshing Terraform state in-memory prior to plan...
253-
The refreshed state will be used to calculate this plan, but will not be
254-
persisted to local or remote state storage.
255-
256-
cloudflare_page_rule.increase-security-on-expensive-page: Refreshing state... [id=1c13fdb84710c4cc8b11daf7ffcca449]
257-
cloudflare_page_rule.redirect-to-new-db-page: Refreshing state... [id=c5c40ff2dc12416b5fe4d0541980c591]
258-
cloudflare_zone_settings_override.example-com-settings: Refreshing state... [id=e2e6491340be87a3726f91fc4148b126]
259-
cloudflare_record.www: Refreshing state... [id=c38d3103767284e7cd14d5dad3ab8669]
260-
cloudflare_load_balancer_monitor.get-root-https: Refreshing state... [id=4238142473fcd48e89ef1964be72e3e0]
261-
cloudflare_record.www-asia: Refreshing state... [id=fda39d8c9bf909132e82a36bab992864]
262-
cloudflare_load_balancer_pool.www-servers: Refreshing state... [id=906d2a7521634783f4a96c062eeecc6d]
263-
cloudflare_load_balancer.www-lb: Refreshing state... [id=cb94f53f150e5c1a65a07e43c5d4cac4]
264-
265-
------------------------------------------------------------------------
266-
267-
An execution plan has been generated and is shown below.
268-
Resource actions are indicated with the following symbols:
269-
- destroy
270-
271-
Terraform will perform the following actions:
272-
273-
- cloudflare_page_rule.increase-security-on-expensive-page
274-
275-
- cloudflare_page_rule.redirect-to-new-db-page
276-
277-
27872
Plan: 0 to add, 0 to change, 2 to destroy.
27973

280-
------------------------------------------------------------------------
74+
Terraform will perform the following actions:
28175

282-
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
283-
can't guarantee that exactly these actions will be performed if
284-
"terraform apply" is subsequently run.
76+
# cloudflare_page_rule.expensive_endpoint_security will be destroyed
77+
# cloudflare_page_rule.legacy_redirect will be destroyed
28578
```
28679

287-
As expected, Terraform is indicating it will remove the two Page Rules created in the previous step.
80+
As expected, Terraform will remove the two Page Rules that were added in tutorial 5.
28881

289-
### iii. Apply the changes
82+
## 4. Apply the changes
29083

291-
The changes look good. Terraform reverts the Cloudflare configuration when you apply the changes:
84+
Apply the changes to remove the Page Rules from your Cloudflare zone:
29285

29386
```sh
29487
terraform apply --auto-approve
29588
```
296-
29789
```sh output
298-
cloudflare_page_rule.redirect-to-new-db-page: Refreshing state... [id=c5c40ff2dc12416b5fe4d0541980c591]
299-
cloudflare_page_rule.increase-security-on-expensive-page: Refreshing state... [id=1c13fdb84710c4cc8b11daf7ffcca449]
300-
cloudflare_zone_settings_override.example-com-settings: Refreshing state... [id=e2e6491340be87a3726f91fc4148b126]
301-
cloudflare_load_balancer_monitor.get-root-https: Refreshing state... [id=4238142473fcd48e89ef1964be72e3e0]
302-
cloudflare_record.www: Refreshing state... [id=c38d3103767284e7cd14d5dad3ab8669]
303-
cloudflare_record.www-asia: Refreshing state... [id=fda39d8c9bf909132e82a36bab992864]
304-
cloudflare_load_balancer_pool.www-servers: Refreshing state... [id=906d2a7521634783f4a96c062eeecc6d]
305-
cloudflare_load_balancer.www-lb: Refreshing state... [id=cb94f53f150e5c1a65a07e43c5d4cac4]
306-
cloudflare_page_rule.redirect-to-new-db-page: Destroying... [id=c5c40ff2dc12416b5fe4d0541980c591]
307-
cloudflare_page_rule.increase-security-on-expensive-page: Destroying... [id=1c13fdb84710c4cc8b11daf7ffcca449]
308-
cloudflare_page_rule.increase-security-on-expensive-page: Destruction complete after 0s
309-
cloudflare_page_rule.redirect-to-new-db-page: Destruction complete after 1s
90+
cloudflare_page_rule.expensive_endpoint_security: Destroying...
91+
cloudflare_page_rule.legacy_redirect: Destroying...
92+
cloudflare_page_rule.expensive_endpoint_security: Destruction complete after 1s
93+
cloudflare_page_rule.legacy_redirect: Destruction complete after 1s
31094

31195
Apply complete! Resources: 0 added, 0 changed, 2 destroyed.
31296
```
313-
31497
Two resources were destroyed, as expected, and you have rolled back to the previous version.
98+
99+
## 5. Verify the revert
100+
Test that the Page Rules are no longer active:
101+
```bash
102+
# This should now return 404 (no redirect)
103+
curl -I https://www.example.com/old-location.php
104+
105+
# This should return normal response (no Under Attack mode)
106+
curl -I https://www.example.com/expensive-db-call
107+
```
108+
109+
Your configuration has been successfully reverted. The Page Rules are removed, and your zone settings are back to the previous state. Git's version control ensures you can always recover or revert changes safely.

0 commit comments

Comments
 (0)