Manage AnyLB with Terraform
Declare pools, strategies and health checks as code, and promote them through environments.
Last updated: August 29, 2026 · 6 min read
Install the provider
Add the provider to your Terraform configuration and authenticate with an API token supplied through the environment. No other credentials are required.
terraform { required_providers { anylb = { source = "anylb/anylb" version = "~> 2.4" } }} provider "anylb" { # Reads ANYLB_TOKEN from the environment.}Define a pool and a load balancer
A pool groups origins together with a health check. A load balancer binds a hostname to one or more of those pools and selects a routing strategy.
resource "anylb_pool" "api" { name = "api-prod" strategy = "latency" origin { address = "api-sin1.internal" weight = 100 } origin { address = "api-fra1.internal" weight = 100 } health_check { path = "/healthz" interval_seconds = 2 timeout_seconds = 1 unhealthy_threshold = 2 }} resource "anylb_load_balancer" "api" { hostname = "api.example.com" pool_ids = [anylb_pool.api.id]}Plan, review, apply
Run a plan to see the exact diff before anything changes. Applied changes propagate to every Cloudflare region within seconds.
$ anylb lb create \ --hostname api.example.com \ --strategy latency \ --origin api-sin1.internal \ --origin api-fra1.internal \ --health-check /healthz --interval 2s ✔ Pool created api-prod (2 origins)✔ Health checks on 3 probe regions✔ Certificate issued api.example.com✔ Load balancer live https://api.example.com Next: point a CNAME at edge.anylb.comDetect and resolve drift
AnyLB records a revision for every change, so a plan against live state will tell you precisely what drifted and when it happened.
Related reading