Cloudflare
terradart_cloudflare wraps the official cloudflare/cloudflare provider (v5) — every resource and data source at its pinned version. Its place in a TerraDart project is the edge around your Dart app: the zone, DNS records, rules and certificates in front of a backend on Cloud Run, AWS or Firebase Hosting, in the same Dart codebase as that backend.
Install
Section titled “Install”dependencies: terradart_core: ^0.36.0 terradart_cloudflare: ^0.36.0Credentials
Section titled “Credentials”CloudflareProvider takes no token, so credentials never enter the synthesized JSON, and synth needs none. terradart plan and terradart apply authenticate with CLOUDFLARE_API_TOKEN (or the other CLOUDFLARE_* variables the provider reads). With them in place, terradart apply synthesizes the Stack and applies it.
A zone in front of your API
Section titled “A zone in front of your API”import 'package:terradart_cloudflare/dns.dart';import 'package:terradart_cloudflare/provider.dart';import 'package:terradart_cloudflare/zone.dart';
final class EdgeStack extends Stack { EdgeStack({required String accountId}) : super( providers: [const CloudflareProvider()], appExports: AppExports('lib/generated/edge_stack.app.dart'), ) { final zone = add(CloudflareZone( 'main', name: .literal('example.com'), account: ZoneAccount(id: .literal(accountId)), )); final api = add(CloudflareDnsRecord( 'api', zoneId: zone.ref, // only a CloudflareZone fits here name: .literal('api.example.com'), type: .cname, ttl: .literal(1), content: .content(.literal('ghs.googlehosted.com')), proxied: .literal(true), )); add(CloudflareDnsRecord( 'sip', zoneId: zone.ref, name: .literal('_sip._tcp.example.com'), type: .srv, ttl: .literal(1), content: .data(.new( priority: .literal(10), weight: .literal(5), port: .literal(5060), target: .literal('sip.example.com'), )), )); addConstant('apiHost', .ref(api.name)); }}The app reads the host it is served from as EdgeStackConstants.apiHost instead of a second copy of the string. The Stack can sit next to a Google, AWS, Azure or Appwrite Stack in the same package, or share one Stack with them by listing both providers.
What the types carry
Section titled “What the types carry”- Enums. Inputs with a fixed value set, such as a DNS record’s
type, are Dart enums (.cname). The sets come from the provider’s documentation and its Go validators, re-extracted on every schema bump. - Sealed choices. Arguments the provider declares mutually exclusive are one sealed argument: a DNS record has
contentor structureddata, written with the.content(...)or the.data(...)variant, as the two records above show. - Typed nested objects. The plugin-framework provider describes objects as nested attributes; each becomes a helper class (
ZoneAccount) rather than aMap. - References. An argument that names another resource takes that resource’s
ref, as the records’zoneIdabove does, and only that type fits. ACloudflareUserGroupMemberstakes the group’srefand, for each member, aUserGroupMemberswith the account member’sref.
Examples
Section titled “Examples”examples/cloudflare_dns_quickstart— the zone and record above, runnable.examples/cloudflare_leftover_quickstart— every other factory with placeholder values; it synthesizes and validates, but is never applied.
Reference
Section titled “Reference”terradart_cloudflareAPI docs- Cloudflare coverage — every factory, its barrel and its example
lib/src/_catalog.g.dart— Terraform type → Dart class and import, for every factory