Skip to content

RulesList

Source: src/Cloudflare/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.

IP list with items

const blocklist = yield* Cloudflare.RulesList("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.RulesList("bad-asns", {
name: "bad_asns",
kind: "asn",
items: [{ asn: 64496 }, { asn: 64511, comment: "spam network" }],
});

Redirect list for Bulk Redirects

const redirects = yield* Cloudflare.RulesList("redirects", {
kind: "redirect",
items: [
{
redirect: {
sourceUrl: "example.com/old",
targetUrl: "https://example.com/new",
statusCode: "301",
},
},
],
});
const list = yield* Cloudflare.RulesList("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}`);