Skip to content

Commit aa36adf

Browse files
Ashnayakdcpena
andauthored
Update configure-https-settings.mdx (#24703)
* Update configure-https-settings.mdx * Update src/content/docs/terraform/tutorial/configure-https-settings.mdx Co-authored-by: Denise Peña <[email protected]> --------- Co-authored-by: Denise Peña <[email protected]>
1 parent a71e40a commit aa36adf

File tree

1 file changed

+61
-212
lines changed

1 file changed

+61
-212
lines changed

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

Lines changed: 61 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -10,256 +10,105 @@ head:
1010

1111
import { Render } from "~/components";
1212

13-
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.
13+
After setting up basic DNS records, you can configure zone settings using Terraform. This tutorial shows how to enable [TLS 1.3](/ssl/edge-certificates/additional-options/tls-13/), [Automatic HTTPS Rewrites](/ssl/edge-certificates/additional-options/automatic-https-rewrites/), and [Strict SSL mode](/ssl/origin-configuration/ssl-modes/full-strict/) using the updated v5 provider.
1414

15-
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.
15+
## Prerequisites
16+
- Completed tutorials [1](/terraform/tutorial/initialize-terraform/) and [2](/terraform/tutorial/track-history/)
17+
- Valid SSL certificate on your origin server (use the [Cloudflare Origin CA](/ssl/origin-configuration/origin-ca/) to generate one for strict SSL mode)
1618

17-
<Render file="v4-code-snippets" product="terraform" />
19+
## 1. Create zone setting configuration
1820

19-
## 1. Create a new branch and append the new zone settings
20-
21-
In this step, modify the Terraform configuration to enable the following settings:
22-
23-
- [TLS 1.3](/ssl/edge-certificates/additional-options/tls-13/)
24-
- [Automatic HTTPS Rewrites](/ssl/edge-certificates/additional-options/automatic-https-rewrites/)
25-
- [Strict SSL mode](/ssl/origin-configuration/ssl-modes/full-strict/)
26-
27-
Strict mode requires a valid SSL certificate on your origin — use the [Cloudflare Origin CA](/ssl/origin-configuration/origin-ca/) to generate one.
21+
Create a new branch and add zone settings:
2822

2923
```bash
30-
git checkout -b step3-https
31-
```
32-
33-
```sh output
34-
Switched to a new branch 'step3-https'
35-
```
36-
37-
```sh
38-
cat >> cloudflare.tf <<'EOF'
24+
git checkout -b step3-zone-setings
25+
```
26+
Add the following to your `main.tf` file:
27+
```hcl
28+
# Enable TLS 1.3
29+
resource "cloudflare_zone_setting" "tls_1_3" {
30+
zone_id = var.zone_id
31+
setting_id = "tls_1_3"
32+
value = "on"
33+
}
3934
40-
resource "cloudflare_zone_settings_override" "example-com-settings" {
41-
zone_id = var.zone_id
35+
# Enable automatic HTTPS rewrites
36+
resource "cloudflare_zone_setting" "automatic_https_rewrites" {
37+
zone_id = var.zone_id
38+
setting_id = "automatic_https_rewrites"
39+
value = "on"
40+
}
4241
43-
settings {
44-
tls_1_3 = "on"
45-
automatic_https_rewrites = "on"
46-
ssl = "strict"
47-
}
42+
# Set SSL mode to strict
43+
resource "cloudflare_zone_setting" "ssl" {
44+
zone_id = var.zone_id
45+
setting_id = "ssl"
46+
value = "strict"
4847
}
49-
EOF
5048
```
5149

52-
## 2. Preview and merge the changes
50+
## 2. Preview and apply the changes
5351

54-
Review what Terraform is proposing before applying changes. The example output below is being filtered to ignore computed values — in this case, settings that will keep their default values.
52+
Review the proposed changes:
5553

5654
```sh
57-
terraform plan | grep -v "(known after apply)"
55+
terraform plan
5856
```
57+
Expected output
5958

6059
```sh output
61-
Refreshing Terraform state in-memory prior to plan...
62-
The refreshed state will be used to calculate this plan, but will not be
63-
persisted to local or remote state storage.
64-
65-
cloudflare_record.www: Refreshing state... [id=c38d3103767284e7cd14d5dad3ab8668]
66-
67-
------------------------------------------------------------------------
68-
69-
An execution plan has been generated and is shown below.
70-
Resource actions are indicated with the following symbols:
71-
+ create
60+
Plan: 3 to add, 0 to change, 0 to destroy.
7261

7362
Terraform will perform the following actions:
7463

75-
# cloudflare_zone_settings_override.example-com-settings will be created
76-
+ resource "cloudflare_zone_settings_override" "example-com-settings" {
77-
+ zone_id = "<ZONE_ID>"
78-
79-
+ settings {
80-
+ automatic_https_rewrites = "on"
81-
+ ssl = "strict"
82-
+ tls_1_3 = "on"
83-
84-
# (...)
85-
}
86-
}
87-
88-
Plan: 1 to add, 0 to change, 0 to destroy.
89-
90-
------------------------------------------------------------------------
91-
92-
Note: You didn't use the -out option to save this plan, so Terraform can't
93-
guarantee to take exactly these actions if you run "terraform apply" now.
94-
```
95-
96-
The proposed changes look good, so you can merge them into the `master` branch and then apply them with `terraform apply`. When working on a team, you may want to require pull requests and use this opportunity to peer review any proposed configuration changes.
97-
98-
```sh
99-
git add cloudflare.tf
100-
git commit -m "Step 3 - Enable TLS 1.3, Always Use HTTPS, and SSL Strict mode."
101-
```
102-
103-
```sh output
104-
[step3-https d540600] Step 3 - Enable TLS 1.3, Always Use HTTPS, and SSL Strict mode.
105-
1 file changed, 11 insertions(+)
106-
```
107-
108-
```sh
109-
git checkout master
110-
```
111-
112-
```sh output
113-
Switched to branch 'master'
114-
```
64+
# cloudflare_zone_setting.automatic_https_rewrites will be created
65+
+ resource "cloudflare_zone_setting" "automatic_https_rewrites" {
66+
+ setting_id = "automatic_https_rewrites"
67+
+ value = "on"
68+
+ zone_id = "your-zone-id"
69+
}
11570

116-
```sh
117-
git merge step3-https
118-
```
71+
# cloudflare_zone_setting.ssl will be created
72+
+ resource "cloudflare_zone_setting" "ssl" {
73+
+ setting_id = "ssl"
74+
+ value = "strict"
75+
+ zone_id = "your-zone-id"
76+
}
11977

120-
```sh output
121-
Updating d26f40b..d540600
122-
Fast-forward
123-
cloudflare.tf | 11 +++++++++++
124-
1 file changed, 11 insertions(+)
78+
# cloudflare_zone_setting.tls_1_3 will be created
79+
+ resource "cloudflare_zone_setting" "tls_1_3" {
80+
+ setting_id = "tls_1_3"
81+
+ value = "on"
82+
+ zone_id = "your-zone-id"
83+
}
12584
```
85+
Commit and merge the changes:
12686

127-
```sh
87+
```bash
88+
git add main.tf
89+
git commit -m "Enable TLS 1.3, automatic HTTPS rewrites, and strict SSL"
90+
git checkout main
91+
git merge step3-zone-settings
12892
git push
12993
```
130-
131-
```sh output
132-
Counting objects: 3, done.
133-
Delta compression using up to 8 threads.
134-
Compressing objects: 100% (3/3), done.
135-
Writing objects: 100% (3/3), 501 bytes | 0 bytes/s, done.
136-
Total 3 (delta 1), reused 0 (delta 0)
137-
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
138-
To [email protected]:$GITHUB_USER/cf-config.git
139-
d26f40b..d540600 master -> master
140-
```
141-
142-
## 3. Apply and verify the changes
143-
14494
Before applying the changes, try to connect with TLS 1.3. Technically, you should not be able to with default settings. To follow along with this test, you will need to [compile `curl` against BoringSSL](https://everything.curl.dev/source/build/tls/boringssl#build-boringssl).
14595

14696
```sh
14797
curl -v --tlsv1.3 https://www.example.com 2>&1 | grep "SSL connection\|error"
14898
```
149-
150-
```sh output
151-
* error:1000042e:SSL routines:OPENSSL_internal:TLSV1_ALERT_PROTOCOL_VERSION
152-
curl: (35) error:1000042e:SSL routines:OPENSSL_internal:TLSV1_ALERT_PROTOCOL_VERSION
153-
```
154-
15599
As shown above, you should receive an error because TLS 1.3 is not yet enabled on your zone. Enable it by running `terraform apply` and try again.
156100

157-
```sh
158-
terraform apply --auto-approve
159-
```
160-
161-
```sh output
162-
163-
Terraform used the selected providers to generate the following execution plan.
164-
Resource actions are indicated with the following symbols:
165-
+ create
166-
167-
Terraform will perform the following actions:
168-
169-
# cloudflare_zone_settings_override.example-com-settings will be created
170-
+ resource "cloudflare_zone_settings_override" "example-com-settings" {
171-
+ id = (known after apply)
172-
+ initial_settings = (known after apply)
173-
+ initial_settings_read_at = (known after apply)
174-
+ readonly_settings = (known after apply)
175-
+ zone_id = "e2e6491340be87a3726f91fc4148b126"
176-
+ zone_status = (known after apply)
177-
+ zone_type = (known after apply)
101+
Apply the configuration:
178102

179-
+ settings {
180-
+ always_online = (known after apply)
181-
+ always_use_https = (known after apply)
182-
+ automatic_https_rewrites = "on"
183-
+ binary_ast = (known after apply)
184-
+ brotli = (known after apply)
185-
+ browser_cache_ttl = (known after apply)
186-
+ browser_check = (known after apply)
187-
+ cache_level = (known after apply)
188-
+ challenge_ttl = (known after apply)
189-
+ ciphers = (known after apply)
190-
+ cname_flattening = (known after apply)
191-
+ development_mode = (known after apply)
192-
+ early_hints = (known after apply)
193-
+ email_obfuscation = (known after apply)
194-
+ filter_logs_to_cloudflare = (known after apply)
195-
+ h2_prioritization = (known after apply)
196-
+ hotlink_protection = (known after apply)
197-
+ http2 = (known after apply)
198-
+ http3 = (known after apply)
199-
+ image_resizing = (known after apply)
200-
+ ip_geolocation = (known after apply)
201-
+ ipv6 = (known after apply)
202-
+ log_to_cloudflare = (known after apply)
203-
+ max_upload = (known after apply)
204-
+ min_tls_version = (known after apply)
205-
+ mirage = (known after apply)
206-
+ opportunistic_encryption = (known after apply)
207-
+ opportunistic_onion = (known after apply)
208-
+ orange_to_orange = (known after apply)
209-
+ origin_error_page_pass_thru = (known after apply)
210-
+ origin_max_http_version = (known after apply)
211-
+ polish = (known after apply)
212-
+ prefetch_preload = (known after apply)
213-
+ privacy_pass = (known after apply)
214-
+ proxy_read_timeout = (known after apply)
215-
+ pseudo_ipv4 = (known after apply)
216-
+ response_buffering = (known after apply)
217-
+ rocket_loader = (known after apply)
218-
+ security_level = (known after apply)
219-
+ server_side_exclude = (known after apply)
220-
+ sort_query_string_for_cache = (known after apply)
221-
+ ssl = "strict"
222-
+ tls_1_2_only = (known after apply)
223-
+ tls_1_3 = "on"
224-
+ tls_client_auth = (known after apply)
225-
+ true_client_ip_header = (known after apply)
226-
+ universal_ssl = (known after apply)
227-
+ visitor_ip = (known after apply)
228-
+ waf = (known after apply)
229-
+ webp = (known after apply)
230-
+ websockets = (known after apply)
231-
+ zero_rtt = (known after apply)
232-
233-
+ mobile_redirect {
234-
+ mobile_subdomain = (known after apply)
235-
+ status = (known after apply)
236-
+ strip_uri = (known after apply)
237-
}
238-
239-
+ security_header {
240-
+ enabled = (known after apply)
241-
+ include_subdomains = (known after apply)
242-
+ max_age = (known after apply)
243-
+ nosniff = (known after apply)
244-
+ preload = (known after apply)
245-
}
246-
}
247-
}
248-
249-
Plan: 1 to add, 0 to change, 0 to destroy.
250-
cloudflare_zone_settings_override.example-com-settings: Creating...
251-
cloudflare_zone_settings_override.example-com-settings: Still creating... [10s elapsed]
252-
cloudflare_zone_settings_override.example-com-settings: Creation complete after 14s [id=e2e6491340be87a3726f91fc4148b126]
253-
254-
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
103+
```sh
104+
terraform apply
255105
```
106+
Type `yes` when prompted.
256107

108+
## 3. Verify the settings
257109
Try the same command as before. The command will now succeed.
258110

259111
```sh
260112
curl -v --tlsv1.3 https://www.example.com 2>&1 | grep "SSL connection\|error"
261113
```
262114

263-
```sh output
264-
* SSL connection using TLSv1.3 / AEAD-AES128-GCM-SHA256
265-
```

0 commit comments

Comments
 (0)