Cloudflare.Rules reference
Source:
packages/cloudflare/src/Rules/List.ts
A Cloudflare account-level List (Lists API) — a named collection of IP
addresses, ASNs, hostnames, or URL redirects referenced from ruleset
expressions (ip.src in $my_list) and Bulk Redirect rules.
name and kind are immutable and changing either triggers a
replacement. The list’s items are managed as part of the resource: on any
change the full contents are replaced via the asynchronous bulk items
operation, which the provider polls to completion.
List: Creating a List
Section titled “List: Creating a List”IP list with items
const blocklist = yield* Cloudflare.Rules.List("blocklist", { kind: "ip", description: "Known bad actors", items: [ { ip: "203.0.113.7", comment: "scanner" }, { ip: "198.51.100.0/24" }, ],});ASN list with an explicit name
const asns = yield* Cloudflare.Rules.List("bad-asns", { name: "bad_asns", kind: "asn", items: [{ asn: 64496 }, { asn: 64511, comment: "spam network" }],});List: Bulk Redirects
Section titled “List: Bulk Redirects”A zone’s http_request_dynamic_redirect phase caps the number of rules
(10 on most plans). Bulk Redirects scale past that: put every mapping in a
redirect list and reference it from a single rule in the account’s
http_request_redirect phase.
const retired = yield* Cloudflare.Rules.List("RetiredSlugs", { kind: "redirect", items: [ { redirect: { sourceUrl: "example.com/services/old-slug", targetUrl: "https://example.com/services/new-slug", statusCode: 301, preserveQueryString: true, }, }, ],});
yield* Cloudflare.Ruleset.AccountEntrypoint("BulkRedirects", { phase: "http_request_redirect", rules: [ { ref: "retired_slugs", expression: Output.interpolate`http.request.full_uri in $${retired.name}`, action: "redirect", actionParameters: { fromList: { name: retired.name, key: "http.request.full_uri" }, }, }, ],});List: Referencing a List from rules
Section titled “List: Referencing a List from rules”const list = yield* Cloudflare.Rules.List("blocklist", { kind: "ip" });
// The stable `name` attribute interpolates into rule expressions:// `ip.src in $<name>`const expression = list.name.apply((name) => `ip.src in $${name}`);List: Looking up an existing List
Section titled “List: Looking up an existing List”List.lookup reads a list Alchemy doesn’t manage (created in the
dashboard or by another stack), found by listId or name, so rules can
reference it. It is read during plan/deploy and never created, updated
or deleted.
const blocklist = Cloudflare.Rules.List.lookup({ name: "blocklist" });const expression = Output.interpolate`ip.src in $${blocklist.name}`;