Cloudflare

From TerminalSkills/skills · View interactive version

Cloudflare is an AI agent skill from the GitHub repository TerminalSkills/skills. Cloudflare is a global network that sits in front of a website or API to provide DNS, CDN caching, DDoS protection, TLS and WAF, and runs serverless code at the edge with Workers. Use this skill when a user asks to put a site behind Cloudflare, create or script DNS records, choose an SSL/TLS encrypt

How to use this skill

Skill file

Cloudflare

Overview

Cloudflare provides DNS, a proxying CDN, DDoS protection, TLS, WAF and edge compute (Workers). Checked on 2026-10-24 against developers.cloudflare.com: Terraform provider 5.28.1 and Wrangler 4.152.0 are current.

Instructions

Step 1: DNS records through the API

Change the domain's nameservers to the two Cloudflare assigns when you add the zone. Then create an API token (dashboard: My Profile > API Tokens, the "Edit zone DNS" template) scoped to the one zone, and keep it in the environment.

export CLOUDFLARE_API_TOKEN="..."   # from your secret store
export ZONE_ID="023e105f4ecef8ad9ca31a8372d0c353"

curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"type":"A","name":"app","content":"203.0.113.10","ttl":1,"proxied":true}'

ttl: 1 means automatic (proxied records are always automatic). proxied: true is the orange cloud: traffic goes through Cloudflare; false is DNS only. Proxy status applies to A, AAAA and CNAME records only.

Step 2: SSL/TLS encryption mode

The mode controls the Cloudflare-to-origin connection. In the dashboard under SSL/TLS > Overview, Automatic SSL/TLS is the default (zones not yet migrated show only Custom), and it picks the most secure mode the origin supports and never downgrades. To choose yourself, use Custom SSL/TLS:

Step 3: Terraform (provider v5)

In provider v5 the resource is cloudflare_dns_record (the old cloudflare_record is the v4 name) and ttl is required.

# cloudflare.tf
terraform {
  required_providers {
    cloudflare = { source = "cloudflare/cloudflare", version = "~> 5.0" }
  }
}

provider "cloudflare" {} # reads CLOUDFLARE_API_TOKEN from the environment

resource "cloudflare_dns_record" "app" {
  zone_id = var.cloudflare_zone_id
  name    = "app"
  content = "203.0.113.10"
  type    = "A"
  ttl     = 1
  proxied = true
}

Step 4: Workers (edge compute)

Scaffold with npm create cloudflare@latest -- status-worker, run locally with npx wrangler dev, and publish with npx wrangler deploy. The project config is wrangler.jsonc.

// src/index.js
export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url)
    if (url.pathname === '/api/health') {
      return new Response('OK', { status: 200 })
    }
    return fetch(request)    // pass through to the origin
  }
}

Examples

Example 1: Put a new site behind Cloudflare

User request: "Add app.northwind-labs.dev to Cloudflare, proxied, pointing at 203.0.113.10."

Add the zone, switch nameservers at the registrar, run the Step 1 curl, then confirm with curl -sI https://app.northwind-labs.dev (a server: cloudflare header means traffic is proxied). Install a Cloudflare Origin CA certificate on the origin and set Full (strict).

Example 2: Health endpoint at the edge

User request: "Answer /api/health from Cloudflare without hitting my server."

Create the Worker from Step 4 with npm create cloudflare@latest, add a route for the zone in wrangler.jsonc, run npx wrangler deploy, and curl https://app.northwind-labs.dev/api/health returns OK.

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.