@stacksolo/plugin-cloudflare
v0.1.0
Published
Cloudflare plugin for StackSolo - provides DNS and CDN resource definitions using CDK for Terraform
Maintainers
Readme
@stacksolo/plugin-cloudflare
Cloudflare DNS integration for StackSolo. Automatically create DNS records pointing to your GCP load balancer.
Features
- Automatic DNS setup - No manual Cloudflare dashboard configuration
- Cloudflare proxy - Enable orange-cloud CDN and DDoS protection
- Load balancer integration - Automatically point domain to LB IP
- Free tier - Cloudflare DNS is free
Installation
pnpm add @stacksolo/plugin-cloudflareQuick Start
- Get your Cloudflare Zone ID from the dashboard (Overview tab, bottom right)
- Create an API token with "Edit zone DNS" permissions
- Store the token as a secret
# Store Cloudflare API token
echo -n "your-cloudflare-api-token" | gcloud secrets create cloudflare-api-token --data-file=-- Add to your config:
{
"project": {
"plugins": [
"@stacksolo/plugin-gcp-cdktf",
"@stacksolo/plugin-cloudflare"
],
"cloudflare": {
"zoneId": "your-zone-id",
"apiToken": "@secret/cloudflare-api-token"
},
"networks": [{
"name": "main",
"loadBalancer": {
"name": "gateway",
"domain": "app.example.com",
"enableHttps": true,
"dns": {
"provider": "cloudflare",
"proxied": true
}
}
}]
}
}Resources
DNS Record (cloudflare:dns_record)
Create DNS records in Cloudflare.
{
type: 'cloudflare:dns_record',
name: 'app-dns',
config: {
zoneId: 'abc123',
recordName: 'app',
type: 'A',
value: '${gatewayIp.address}', // Reference to load balancer IP
proxied: true,
ttl: 1 // Auto TTL when proxied
}
}Configuration Reference
DNS Record Options
| Property | Type | Required | Default | Description |
|----------|------|----------|---------|-------------|
| name | string | Yes | - | Resource name |
| zoneId | string | Yes | - | Cloudflare Zone ID |
| recordName | string | Yes | - | DNS name (e.g., "app" for app.example.com) |
| type | string | Yes | A | Record type: A, AAAA, or CNAME |
| value | string | Yes | - | IP address or CDKTF reference |
| proxied | boolean | No | true | Enable Cloudflare proxy (orange cloud) |
| ttl | number | No | 1 | TTL in seconds (1 = auto when proxied) |
Load Balancer Integration
When using with @stacksolo/plugin-gcp-cdktf, add dns config to your load balancer:
{
"loadBalancer": {
"name": "gateway",
"domain": "app.example.com",
"enableHttps": true,
"dns": {
"provider": "cloudflare",
"proxied": true
}
}
}The load balancer will automatically:
- Create a Cloudflare DNS record
- Point it to the load balancer IP
- Enable Cloudflare proxy if specified
Prerequisites
- Cloudflare account - Free tier works
- Domain on Cloudflare - DNS must be managed by Cloudflare
- API token - With "Edit zone DNS" permission
- Terraform - Required for CDKTF deployment
Getting Your Zone ID
- Log into Cloudflare dashboard
- Select your domain
- Scroll down on the Overview page
- Zone ID is in the right sidebar under "API"
Creating an API Token
- Go to Cloudflare dashboard → Profile → API Tokens
- Click "Create Token"
- Use "Edit zone DNS" template
- Select your zone under "Zone Resources"
- Create token and save it securely
Cost
| Resource | Monthly Cost | |----------|-------------| | DNS Records | Free | | Cloudflare Proxy | Free (Pro features paid) |
License
MIT
