Cloudflare: 🛠️ Migrating 🌐 Load Balancing Configuration Between Accounts
2 min readDec 18, 2024
This guide explains how to migrate 🔄 Load Balancers, Pools 🏊, and Monitors 🖥️ from one Cloudflare account to another using API calls. 🧰
📋 Prerequisites
Before starting, ensure you have 🔑 API tokens for both source and destination accounts.
Permissions:
Load Balancers: Readfor the source account.Load Balancers: Write,Load Balancing Monitors: Write, andLoad Balancing Pools: Writefor the destination account.
export SOURCE_CLOUDFLARE_EMAIL=“<source-email>”
export SOURCE_CLOUDFLARE_API_KEY=“<source-api-key>”
export DESTINATION_CLOUDFLARE_EMAIL=“<destination-email>”
export DESTINATION_CLOUDFLARE_API_KEY=“<destination-api-key>”
export SOURCE_ACCOUNT_ID=“<source-account-id>”
export DESTINATION_ACCOUNT_ID=“<destination-account-id>”
export SOURCE_ZONE_ID=“<source-zone-id>”
export DESTINATION_ZONE_ID=“<destination-zone-id>”Step 1: Get Configuration from the Source Account
GET Load Balancers
curl https://api.cloudflare.com/client/v4/zones/$SOURCE_ZONE_ID/load_balancers \
-H “X-Auth-Email: $SOURCE_CLOUDFLARE_EMAIL” \
-H “X-Auth-Key: $SOURCE_CLOUDFLARE_API_KEY” \
-H “Content-Type: application/json” > jinnabalu_lb.jsonGet Pools 🏊
curl https://api.cloudflare.com/client/v4/accounts/$SOURCE_ACCOUNT_ID/load_balancers/pools \
-H “X-Auth-Email: $SOURCE_CLOUDFLARE_EMAIL” \
-H “X-Auth-Key: $SOURCE_CLOUDFLARE_API_KEY” \
-H “Content-Type: application/json” > jinnabalu_pools.jsonGet Monitors 🖥️
curl https://api.cloudflare.com/client/v4/accounts/$SOURCE_ACCOUNT_ID/load_balancers/monitors \
-H “X-Auth-Email: $SOURCE_CLOUDFLARE_EMAIL” \
-H “X-Auth-Key: $SOURCE_CLOUDFLARE_API_KEY” \
-H “Content-Type: application/json” > jinnabalu_monitors.jsonStep 2: 🛠️ POST Resources in the Destination Account
POST Monitors 🖥️
curl -X POST https://api.cloudflare.com/client/v4/accounts/$DESTINATION_ACCOUNT_ID/load_balancers/monitors \
-H ‘Content-Type: application/json’ \
-H “X-Auth-Email: $DESTINATION_CLOUDFLARE_EMAIL” \
-H “X-Auth-Key: $DESTINATION_CLOUDFLARE_API_KEY” \
-d @jinnabalu_monitors.jsonPOST Pools 🏊
curl -X POST https://api.cloudflare.com/client/v4/accounts/$DESTINATION_ACCOUNT_ID/load_balancers/pools \
-H ‘Content-Type: application/json’ \
-H “X-Auth-Email: $DESTINATION_CLOUDFLARE_EMAIL” \
-H “X-Auth-Key: $DESTINATION_CLOUDFLARE_API_KEY” \
-d @jinnabalu_pools.jsonPOST Load Balancers
curl -X POST https://api.cloudflare.com/client/v4/zones/$DESTINATION_ZONE_ID/load_balancers \
-H ‘Content-Type: application/json’ \
-H “X-Auth-Email: $DESTINATION_CLOUDFLARE_EMAIL” \
-H “X-Auth-Key: $DESTINATION_CLOUDFLARE_API_KEY” \
-d @jinnabalu_lb.json💡 Tips for Automation
- 🔄 Iterate Over Multiple Zones:
- Fetch and create configurations for multiple zones by looping through a list of
$SOURCE_ZONE_IDand$DESTINATION_ZONE_IDpairs.
