有时,您可能需要回滚配置更改。例如,您可能希望在新的配置上运行性能测试,或者也许您输错了一个 IP 地址并导致您的整个站点瘫痪。
要还原您的配置,请检出所需的分支,并让 Terraform 将您的 Cloudflare 设置移回过去。如果您意外地导致站点瘫痪,请考虑建立一个良好的策略来对拉取请求进行同行评审,而不是像教程中为了简明扼要而那样直接合并到 master 中。
在确定要还原到多远之前,请检查您的 Git 历史记录:
git log --onelinef1a2b3c Step 5 - Add two Page Rules
d4e5f6g Step 4 - Create load balancer (LB) monitor, LB pool, and LB
a7b8c9d Step 3 - Enable TLS 1.3, automatic HTTPS rewrites, and strict SSL
e1f2g3h Step 2 - Initial Terraform v5 configuration将 Cloudflare 配置存储在 Git 中的另一个好处是,您可以查看是谁做出了更改。如果您对拉取请求进行同行评审,您还可以查看是谁评审并批准了更改。
git log检查最后一次更改的时间:
git show这将显示最近的提交以及更改了哪些文件。
假设在您遵循使用页面规则添加异常教程部署页面规则不久后,有人告诉您该 URL 不再需要了,安全设置和重定向也应该被丢弃。
虽然您始终可以直接编辑配置文件并删除这些条目,但您可以使用 Git 帮您做到这一点。
使用 Git 创建一个还原提交来撤消页面规则的更改:
git revert HEADGit 将使用您的默认编辑器打开一条提交消息。保存并关闭以接受默认消息,或者对其进行自定义:
Revert "Add Page Rules for security and redirects"
This reverts commit f1a2b3c4d5e6f7a8b9c0d1e2f3g4h5i6j7k8l9m0.检查 Terraform 将对已还原的配置执行什么操作:
terraform plan预期输出:
Plan: 0 to add, 0 to change, 2 to destroy.
Terraform will perform the following actions:
# cloudflare_page_rule.expensive_endpoint_security will be destroyed
# cloudflare_page_rule.legacy_redirect will be destroyed如预期的那样,Terraform 将删除教程 5 中添加的两条页面规则。
应用更改以从您的 Cloudflare 区域中删除页面规则:
terraform apply --auto-approvecloudflare_page_rule.expensive_endpoint_security: Destroying...
cloudflare_page_rule.legacy_redirect: Destroying...
cloudflare_page_rule.expensive_endpoint_security: Destruction complete after 1s
cloudflare_page_rule.legacy_redirect: Destruction complete after 1s
Apply complete! Resources: 0 added, 0 changed, 2 destroyed.如预期的那样,两个资源已被销毁,并且您已经回滚到以前的版本。
测试页面规则不再处于活动状态:
# 这现在应该返回 404 (无重定向)
curl -I https://www.example.com/old-location.php
# 这应该返回正常响应 (无 Under Attack 模式)
curl -I https://www.example.com/expensive-db-call您的配置已成功还原。页面规则已被删除,您的区域设置已恢复到以前的状态。Git 的版本控制可确保您始终能够安全地恢复或还原更改。