Pulumi Cloudflare Provider
repository·master·Indexed 41 days ago
https://github.com/pulumi/pulumi-cloudflareManage Cloudflare resources, such as DNS records and rulesets, using Infrastructure as Code in TypeScript, Python, Go, .NET, and Java. This provider is a derived work of the Cloudflare Terraform provider and supports authentication via API Tokens, API Keys, or User Service Keys.
What's inside Pulumi Cloudflare
- The Pulumi Cloudflare provider is a package designed for creating and managing Cloudflare cloud resources using Pulumi's Infrastructure as Code (IaC) capabilities. It allows you to define and provision Cloudflare configurations (such as DNS records, rulesets, and other cloud resources) using familiar programming languages like C#, Python, Go, TypeScript, and Java.
Use the Pulumi Cloudflare provider
masterThepulumi-cloudflarepackage allows you to create and manage Cloudflare cloud resources using Pulumi's Infrastructure as Code (IaC) capabilities. It is a derived work of the Cloudflare Terraform provider, providing access to Cloudflare's extensive API surface through Pulumi's programming models in .NET, Python, Go, TypeScript, and Java.Install the Cloudflare provider
masterThe Cloudflare provider is available as a package for all supported Pulumi languages. Choose the package corresponding to your runtime:
- JavaScript/TypeScript:
@pulumi/cloudflare - Python:
pulumi-cloudflare - Go:
github.com/pulumi/pulumi-cloudflare/sdk/v6/go/cloudflare - .NET:
Pulumi.Cloudflare - Java:
com.pulumi/cloudflare
- JavaScript/TypeScript:
Install the Cloudflare Pulumi package
masterInstall the Cloudflare provider package using the package manager corresponding to your programming language. Ensure you have the Pulumi CLI installed first.
### Node.js (Java/TypeScript) $ npm install @pulumi/cloudflare # or $ yarn add @pulumi/cloudflare ### Python $ pip install pulumi_cloudflare ### Go $ go get github.com/pulumi/pulumi-cloudflare/sdk/v6 ### .NET $ dotnet add package Pulumi.CloudflareMigrate from version 0.x to 1.0.0
masterThe release of version 1.0.0 introduced several breaking changes to provider configuration and environment variables. If you are upgrading from a version prior to 1.0.0, you must apply the following changes:
### BREAKING CHANGES (v1.0.0): * provider configuration option `token` has been renamed to `api_key`. * provider configuration option `org_id` has been renamed to `account_id` and is now required. * provider configuration option `use_org_from_zone` has been removed. * environment variable `CLOUDFLARE_TOKEN` has been renamed to `CLOUDFLARE_API_TOKEN`. * environment variable `CLOUDFLARE_ORG_ID` has been renamed to `CLOUDFLARE_ACCOUNT_ID`. * environment variable `CLOUDFLARE_ORG_ZONE` has been removed. * `zone_id` is now a required parameter in all resourcesDisable provider preview functionality
masterIn version 2.7.0 and later, the provider includes improved preview functionality that provides a more accurate understanding of actual changes. If you need to revert to the previous behavior, you can disable this feature by setting the
PULUMI_DISABLE_PROVIDER_PREVIEWenvironment variable to1orfalse.export PULUMI_DISABLE_PROVIDER_PREVIEW=1Configure Cloudflare authentication
masterThe Cloudflare provider requires authentication to perform operations. You can provide credentials via Pulumi configuration or environment variables.
Important Authentication Rules:
- You must provide exactly one of
cloudflare:apiKey,cloudflare:apiToken, orcloudflare:apiUserServiceKey. - If using
cloudflare:apiKey, you must also providecloudflare:email. cloudflare:apiTokenis the recommended modern method;cloudflare:apiKeyis considered legacy.
Config Key Env Var Description cloudflare:apiKeyCLOUDFLARE_API_KEYLegacy API key. Requires cloudflare:email.cloudflare:apiTokenCLOUDFLARE_API_TOKENRecommended API Token. cloudflare:apiUserServiceKeyCLOUDFLARE_API_USER_SERVICE_KEYRestricted key for specific endpoints. cloudflare:emailCLOUDFLARE_EMAILRequired when using apiKey.- You must provide exactly one of
Configure Cloudflare provider credentials
masterThe Cloudflare provider requires authentication to interact with Cloudflare resources. You must provide exactly one of the following authentication methods. You can set these via Pulumi configuration or environment variables.
Authentication Options
apiToken(Recommended): The API Token for operations. Use theCLOUDFLARE_API_TOKENenvironment variable or set via Pulumi config.apiKey: The legacy API key. Requires theemailfield to be set. Use theCLOUDFLARE_API_KEYenvironment variable.apiUserServiceKey: A special restricted API key. Use theCLOUDFLARE_API_USER_SERVICE_KEYenvironment variable.
Configuration via Pulumi.yaml
To set the
apiTokenusing Pulumi configuration, add the following to yourPulumi.yaml:config: cloudflare:apiToken: value: 'YOUR_API_TOKEN'config: cloudflare:apiToken: value: 'TODO: var.cloudflare_api_token'Configure Cloudflare provider advanced settings
masterUse the following configuration keys to customize the HTTP client behavior for the Cloudflare provider.
Config Key Env Var Type Description cloudflare:baseUrlCLOUDFLARE_BASE_URLString Overrides the default HTTP client base URL. cloudflare:userAgentOperatorSuffixCLOUDFLARE_USER_AGENT_OPERATOR_SUFFIXString Appends a value to the HTTP User Agent. Defaults to pulumi/<version>. Use an empty string to remove the Pulumi identifier.Resource ID mapping and delegation
masterThe Cloudflare provider uses specific logic to compute resource IDs, often delegating to internal fields to ensure consistency with Cloudflare's API.
Some resources use specific fields as their primary Pulumi ID:
cloudflare_ai_search_instance: UsesaiSearchInstanceId.cloudflare_image: UsesimageId.cloudflare_zero_trust_access_ai_controls_mcp_portal: UseszeroTrustAccessAiControlsMcpPortalId.cloudflare_zero_trust_access_ai_controls_mcp_server: UseszeroTrustAccessAiControlsMcpServerId.cloudflare_zone_setting: UsessettingId.cloudflare_snippet: UsessnippetName.
For resources where the ID is not explicitly provided by the API, the provider attempts to construct it using available context, such as combining
accountIdandzoneId.Migrate Cloudflare resources from v5 to v6
masterThe Cloudflare provider includes
PreStateUpgradeHookandTransformFromStatelogic to handle migrations from version 5 to version 6. If you are upgrading your stack, the following resources have specific schema transformations applied automatically:cloudflare_ruleset: MigratesactionParameters.headersfrom an array to a MapNestedAttribute and updatesactionParameters.rulesfrom amap[string]stringto amap[string][]string.cloudflare_list: Flattens the v5valuewrapper (containingasn,ip,hostnames,redirects) into top-level fields (asn,ip,hostname,redirect).cloudflare_zone: Transformszonetoname,accountIdtoaccount.id, andplantoplan.id.cloudflare_zero_trust_access_application: Migratescors_headersfrom a list to an object andpoliciesfrom a list of strings to a list of objects containingid.cloudflare_zero_trust_access_policy: Migrates boolean and string properties into nested objects (e.g.,includes.certificatebecomes an object).cloudflare_workers_route: Ensures theidfield is populated from thepatternfield ifidis missing.
Create a DNS record
masterYou can manage Cloudflare DNS records using the
DnsRecordresource. Below are examples for various languages.import * as pulumi from "@pulumi/pulumi"; import * as cloudflare from "@pulumi/cloudflare"; // Create a DNS record const www = new cloudflare.DnsRecord("www", {});