Skip to content

Commit 6a755d9

Browse files
andauthored
feat: add guide for creating partial and secondary zones in Terraform (#28940)
* feat: add guide for creating partial and secondary zones in Terraform * chore: add normal partial zone creation flow * chore: use 'subdomain' consistently in Terraform guide Co-authored-by: Cole Arendt <23075542+colearendt@users.noreply.github.com> * chore: use 'subdomain' consistently in Terraform guide Co-authored-by: Cole Arendt <23075542+colearendt@users.noreply.github.com> --------- Co-authored-by: Cole Arendt <23075542+colearendt@users.noreply.github.com>
1 parent 72e1b8c commit 6a755d9

File tree

5 files changed

+131
-2
lines changed

5 files changed

+131
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pcx_content_type: navigation
33
title: Advanced topics
44
sidebar:
5-
order: 5
5+
order: 6
66
group:
77
hideIndex: true
88
---
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Create a partial zone using Terraform
4+
sidebar:
5+
order: 1
6+
label: Create a partial zone
7+
head:
8+
- tag: title
9+
content: Create a partial zone using Terraform
10+
---
11+
12+
import { Tabs, TabItem } from "~/components";
13+
14+
A [partial zone](/dns/zone-setups/partial-setup/) lets you use Cloudflare for a subdomain while keeping your existing authoritative DNS provider for the parent domain. This guide shows how to automate the setup using the [Cloudflare Terraform provider](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs).
15+
16+
:::caution
17+
A partial zone cannot be created in the same Cloudflare account as the parent domain's full zone.
18+
:::
19+
20+
## Prerequisites
21+
22+
- Terraform installed. Refer to [Get started](/terraform/installing/).
23+
- Your Cloudflare account ID and a configured provider block. Refer to [Initialize Terraform](/terraform/tutorial/initialize-terraform/).
24+
25+
## Create the zone
26+
27+
Add the zone configuration and apply the change to create the zone:
28+
29+
```hcl
30+
resource "cloudflare_zone" "subdomain_example_com" {
31+
account = {
32+
id = var.cloudflare_account_id
33+
}
34+
name = "subdomain.example.com"
35+
}
36+
```
37+
38+
Then, in a new Terraform plan and apply cycle, upgrade the zone to a Business plan or higher:
39+
```hcl
40+
resource "cloudflare_zone_subscription" "example_zone_subscription" {
41+
zone_id = cloudflare_zone.subdomain_example_com.id
42+
frequency = "monthly"
43+
rate_plan = {
44+
id = "business"
45+
currency = "USD"
46+
}
47+
}
48+
```
49+
50+
Then, again in a new Terraform plan and apply cycle, update your Terraform configuration to add `type = "partial"` to the zone:
51+
52+
```hcl
53+
resource "cloudflare_zone" "subdomain_example_com" {
54+
account = {
55+
id = var.cloudflare_account_id
56+
}
57+
name = "subdomain.example.com"
58+
type = "partial"
59+
}
60+
```
61+
62+
Terraform places the zone in a **Pending** state. You must add the necessary DNS records and verify domain ownership before Cloudflare activates it.
63+
64+
:::note
65+
Refer to the [cloudflare_zone docs](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/zone) in the Terraform provider documentation when you need to reference other zone properties.
66+
:::
67+
68+
## Related resources
69+
70+
- [Partial zone setup](/dns/zone-setups/partial-setup/)
71+
- [Convert a full zone to partial](/dns/zone-setups/conversions/convert-full-to-partial/)
72+
- [`cloudflare_zone` resource](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/zone)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Create a subdomain zone using Terraform
4+
sidebar:
5+
order: 2
6+
label: Create a subdomain zone
7+
head:
8+
- tag: title
9+
content: Create a subdomain zone using Terraform
10+
---
11+
12+
A [subdomain zone](/dns/zone-setups/subdomain-setup/) lets you manage a subdomain in a separate Cloudflare zone from the parent domain. This is useful for access control and team management. This guide shows how to automate the setup using the [Cloudflare Terraform provider](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs). It is only available for Enterprise accounts
13+
> NOTE: subdomain setup is only available for Enterprise accounts
14+
## Prerequisites
15+
16+
- Terraform installed. Refer to [Get started](/terraform/installing/).
17+
- Your Cloudflare account ID and a configured provider block. Refer to [Initialize Terraform](/terraform/tutorial/initialize-terraform/).
18+
19+
## Create the zone
20+
21+
Create a `cloudflare_zone` resource for the subdomain zone. The following example creates a zone for `subdomain.example.com`:
22+
23+
```hcl
24+
resource "cloudflare_zone" "subdomain_example_com" {
25+
account = {
26+
id = var.cloudflare_account_id
27+
}
28+
name = "subdomain.example.com"
29+
type = "full"
30+
}
31+
```
32+
33+
Terraform creates the zone in a **Pending** state. You must add NS delegation records to the parent zone before Cloudflare activates it.
34+
35+
:::note
36+
Refer to the [cloudflare_zone docs](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/zone) in the Terraform provider documentation when you need to reference other zone properties.
37+
:::
38+
39+
## Related resources
40+
41+
- [Subdomain setup](/dns/zone-setups/subdomain-setup/)
42+
- [`cloudflare_zone` resource](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/zone)
43+
- [`cloudflare_dns_record` resource](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/dns_record)
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: How-to guides
4+
sidebar:
5+
order: 5
6+
group:
7+
hideIndex: true
8+
---
9+
10+
import { DirectoryListing } from "~/components";
11+
12+
The following guides explain how to complete common Terraform tasks.
13+
14+
<DirectoryListing />

src/content/docs/terraform/troubleshooting/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pcx_content_type: navigation
33
title: Troubleshooting
44
sidebar:
5-
order: 6
5+
order: 7
66
group:
77
hideIndex: true
88
---

0 commit comments

Comments
 (0)