Skip to content

Cloudflare Plugin

The @stacksolo/plugin-cloudflare provides automatic DNS configuration for your domains. Point your domain to your GCP load balancer without manual Cloudflare dashboard configuration.

  1. Get your Cloudflare Zone ID from the dashboard
  2. Create an API token with DNS edit permissions
  3. Store the token as a secret
  4. Add the dns config to your load balancer
{
"project": {
"plugins": [
"@stacksolo/plugin-gcp-cdktf",
"@stacksolo/plugin-cloudflare"
],
"cloudflare": {
"zoneId": "your-zone-id-here",
"apiToken": "@secret/cloudflare-api-token"
},
"networks": [{
"name": "main",
"loadBalancer": {
"name": "gateway",
"domain": "app.example.com",
"enableHttps": true,
"dns": {
"provider": "cloudflare",
"proxied": true
}
}
}]
}
}

After deployment:

  • DNS record is automatically created
  • Domain points to load balancer IP
  • Cloudflare proxy enabled (if configured)
ResourceConfig KeyPurpose
DNS Recordcloudflare:dns_recordCreate A, AAAA, or CNAME records

Create DNS records in Cloudflare, typically to point domains to load balancer IPs.

PropertyTypeRequiredDefaultDescription
namestringYes-Resource name
zoneIdstringYes-Cloudflare Zone ID
recordNamestringYes-DNS name (e.g., “app” for app.example.com)
typestringYesARecord type: A, AAAA, or CNAME
valuestringYes-IP address or CDKTF reference
proxiedbooleanNotrueEnable Cloudflare proxy (orange cloud)
ttlnumberNo1TTL in seconds (1 = auto when proxied)
{
"type": "cloudflare:dns_record",
"name": "app-dns",
"config": {
"zoneId": "abc123def456",
"recordName": "app",
"type": "A",
"value": "${gatewayIp.address}",
"proxied": true
}
}

The easiest way to use Cloudflare DNS is through the load balancer’s dns option:

{
"loadBalancer": {
"name": "gateway",
"domain": "app.example.com",
"enableHttps": true,
"dns": {
"provider": "cloudflare",
"proxied": true
}
}
}

This automatically:

  1. Creates a Cloudflare A record
  2. Points it to the load balancer’s IP address
  3. Enables Cloudflare proxy if specified
PropertyTypeRequiredDescription
providerstringYesMust be "cloudflare"
proxiedbooleanNoEnable Cloudflare proxy (default: true)

  1. Log into Cloudflare dashboard
  2. Select your domain
  3. On the Overview page, scroll to the right sidebar
  4. Copy the “Zone ID” value
  1. Go to ProfileAPI Tokens
  2. Click Create Token
  3. Use the “Edit zone DNS” template
  4. Under “Zone Resources”, select your zone
  5. Click Continue to summaryCreate Token
  6. Copy the token (you won’t see it again)
Terminal window
# Create secret in GCP Secret Manager
echo -n "your-cloudflare-api-token" | gcloud secrets create cloudflare-api-token --data-file=-

Add to your stacksolo.config.json:

{
"project": {
"cloudflare": {
"zoneId": "your-zone-id",
"apiToken": "@secret/cloudflare-api-token"
}
}
}

When proxied: true:

  • Traffic routes through Cloudflare’s CDN
  • DDoS protection enabled
  • SSL/TLS managed by Cloudflare
  • Hides your origin server IP
  • Analytics available in Cloudflare dashboard

When proxied: false:

  • DNS-only mode
  • Traffic goes directly to your server
  • Origin IP is visible in DNS lookups
FeatureProxiedNon-Proxied
CDN cachingYesNo
DDoS protectionYesNo
Origin IP hiddenYesNo
Cloudflare analyticsYesNo
Direct connectionNoYes

ResourceMonthly Cost
DNS RecordsFree
Cloudflare ProxyFree tier included

Cloudflare offers a generous free tier. Paid plans add additional features like advanced DDoS protection and analytics.


  1. Cloudflare account - Free tier works
  2. Domain on Cloudflare - DNS must be managed by Cloudflare (nameservers pointed to Cloudflare)
  3. API token - With “Edit zone DNS” permission for your zone
  4. Terraform - Required for CDKTF deployment

”Authentication error” during deployment

Section titled “”Authentication error” during deployment”
  • Verify your API token has “Edit zone DNS” permission
  • Check the token is stored correctly in Secret Manager
  • Ensure the zone ID is correct
  • Cloudflare DNS propagates quickly, but TTL affects caching
  • If proxied, the A record points to Cloudflare IPs (this is expected)
  • Use dig or online DNS checkers to verify

When using Cloudflare proxy with GCP HTTPS load balancer:

  • Cloudflare handles client → Cloudflare SSL
  • GCP handles Cloudflare → Load Balancer SSL
  • Both certificates need to be valid

For simplest setup, use Cloudflare’s “Full (strict)” SSL mode.