Skip to content

Cloudflare.Zone reference

Source: src/Cloudflare/Zone/CustomNameservers.ts

Controls whether a Cloudflare zone uses account-level custom nameservers (ACNS, /zones/{zone_id}/custom_ns).

This configuration is a zone singleton — it always exists on every zone (disabled by default), so the resource never creates or deletes anything physical. Reconcile applies the desired enabled/nsSet when the observed configuration differs; destroy restores the configuration the zone had before Alchemy first managed it.

Enabling requires an account custom nameserver set to be configured first (Business/Enterprise feature). Without one, Cloudflare rejects the update with the typed CustomNameserverSetNotFound error.

CustomNameservers: Enabling account custom nameservers

Section titled “CustomNameservers: Enabling account custom nameservers”

Use the account’s default nameserver set

yield* Cloudflare.Zone.CustomNameservers("CustomNs", {
zoneId: zone.zoneId,
enabled: true,
});

Pin a specific nameserver set

yield* Cloudflare.Zone.CustomNameservers("CustomNs", {
zoneId: zone.zoneId,
enabled: true,
nsSet: 2,
});
yield* Cloudflare.Zone.CustomNameservers("CustomNs", {
zoneId: zone.zoneId,
enabled: false,
});

Source: src/Cloudflare/Zone/Hold.ts

A Cloudflare zone hold (/zones/{zone_id}/hold) — prevents the zone’s hostname (and optionally its subdomains) from being added to another Cloudflare account while the hold is active.

Zone holds are only available on Enterprise zones. On other plans every create/patch fails with Cloudflare code 1005, surfaced as the typed ZoneHoldsRequireEnterprise error.

Destroying the resource removes the hold. The delete is idempotent — removing a hold that is already gone (or whose zone was deleted out-of-band) succeeds.

Place a hold on a zone

const hold = yield* Cloudflare.Zone.Hold("MyHold", {
zoneId: zone.zoneId,
});

Hold the zone and all of its subdomains

yield* Cloudflare.Zone.Hold("MyHold", {
zoneId: zone.zoneId,
includeSubdomains: true,
});
import { adopt } from "alchemy/AdoptPolicy";
// A hold carries no ownership markers, so the engine refuses to take
// over a pre-existing hold unless you opt in with `adopt(true)`.
const hold = yield* Cloudflare.Zone.Hold("MyHold", {
zoneId: zone.zoneId,
}).pipe(adopt(true));

Source: src/Cloudflare/Zone/Setting.ts

A single Cloudflare zone setting (/zones/{zone_id}/settings/{settingId}) pinned to a desired value.

Zone settings are singletons — every setting always exists on every zone (with a Cloudflare default), so this resource never creates or deletes anything physical. Reconcile patches the setting when the observed value differs from the desired one; destroy restores the value the setting had before Alchemy first managed it (captured as initialValue).

Many settings are plan-gated (editable: false on lower plans — e.g. image_resizing, polish need Pro+; advanced_ddos is Enterprise). Patching a non-editable setting fails with Cloudflare’s “setting not editable” error.

Force HTTPS on the whole zone

yield* Cloudflare.Zone.Setting("AlwaysUseHttps", {
zoneId: zone.zoneId,
settingId: "always_use_https",
value: "on",
});

Disable Always Online

yield* Cloudflare.Zone.Setting("AlwaysOnline", {
zoneId: zone.zoneId,
settingId: "always_online",
value: "off",
});
yield* Cloudflare.Zone.Setting("BrowserCacheTtl", {
zoneId: zone.zoneId,
settingId: "browser_cache_ttl",
value: 3600,
});
yield* Cloudflare.Zone.Setting("MinTls", {
zoneId: zone.zoneId,
settingId: "min_tls_version",
value: "1.2",
});

Source: src/Cloudflare/Zone/Zone.ts

A Cloudflare Zone (DNS domain) managed by Alchemy.

Zones default to retain on removal — destroying the stack does NOT delete the zone in Cloudflare. Opt in to actual deletion by wrapping the resource (or the whole stack) in destroy() from alchemy/RemovalPolicy.

Create a new zone

const zone = yield* Cloudflare.Zone.Zone("MyZone", {
name: "example.com",
});

Allow destruction

import { destroy } from "alchemy/RemovalPolicy";
yield* Cloudflare.Zone.Zone("MyZone", { name: "example.com" }).pipe(destroy());
import { adopt } from "alchemy/AdoptPolicy";
// A zone carries no ownership markers, so the engine refuses to take over a
// pre-existing zone unless you opt in with `adopt(true)`.
const zone = yield* Cloudflare.Zone.Zone("MyZone", {
name: "example.com",
}).pipe(adopt(true));
// zone.zoneId, zone.nameServers, zone.accountId, ...