Skip to main content

Cloudflare CDN and WAF in front of an origin

Put Cloudflare's CDN and WAF in front of an origin server

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set cloudflare-ts-cdn-waf
cd pulumi-examples/cloudflare-ts-cdn-waf

Puts Cloudflare in front of an existing origin server: a proxied DNS record routes traffic through Cloudflare, a cache ruleset caches responses at the edge, and a rate-limiting ruleset protects the origin from abuse.

Prerequisites#

  1. Install Pulumi

  2. Install Node.js

  3. A domain already added to Cloudflare as a zone.

  4. Create a Cloudflare API token with DNS and Zone WAF edit permissions, and export it:

    Terminal window
    export CLOUDFLARE_API_TOKEN=<your-token>

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Configure the zone and origin:

    Terminal window
    pulumi config set zoneId <your-zone-id>
    pulumi config set origin origin.example.com
  3. Install dependencies and deploy:

    Terminal window
    npm install
    pulumi up
  4. The proxied hostname is exported as url:

    Terminal window
    pulumi stack output url

Cleaning up#

Terminal window
pulumi destroy
pulumi stack rm dev

Related

The infrastructure as code platform for any cloud.