Sitemap

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. 🧰

cloudflare account to account migration

📋 Prerequisites

Before starting, ensure you have 🔑 API tokens for both source and destination accounts.

Permissions:

  • Load Balancers: Read for the source account.
  • Load Balancers: Write , Load Balancing Monitors: Write, and Load Balancing Pools: Write for 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.json

Get 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.json

Get 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.json

Step 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.json

POST 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.json

POST 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

  1. 🔄 Iterate Over Multiple Zones:
  2. Fetch and create configurations for multiple zones by looping through a list of $SOURCE_ZONE_ID and $DESTINATION_ZONE_ID pairs.

--

--

Jinna Baalu
Jinna Baalu

Written by Jinna Baalu

Devops Solution Architect | Managing Consensus based Distributed Clusters | Centralised Logging 4M/15min | ELK | Prometheus | Kafka | Cassandra | Mongo

No responses yet