Top Related Projects
The AWS Provider enables Terraform to manage AWS resources.
Terraform Provider for Google Cloud Platform
Terraform provider for Azure Resource Manager
Quick Overview
The Cloudflare Terraform Provider is an official plugin for Terraform that allows users to manage Cloudflare resources using infrastructure-as-code principles. It provides a way to automate the creation, modification, and deletion of Cloudflare services and configurations through Terraform.
Pros
- Enables version-controlled, reproducible infrastructure management for Cloudflare resources
- Supports a wide range of Cloudflare products and features
- Regularly updated to include new Cloudflare capabilities
- Well-documented with extensive examples and community support
Cons
- Learning curve for users new to Terraform or infrastructure-as-code concepts
- Some advanced Cloudflare features may not be fully supported or require workarounds
- Potential for rate limiting when managing large numbers of resources
- Occasional breaking changes in major version updates
Code Examples
- Creating a DNS record:
resource "cloudflare_record" "example" {
zone_id = var.cloudflare_zone_id
name = "example.com"
value = "203.0.113.10"
type = "A"
proxied = true
}
- Configuring a Page Rule:
resource "cloudflare_page_rule" "example" {
zone_id = var.cloudflare_zone_id
target = "example.com/api/*"
actions {
ssl = "strict"
cache_level = "aggressive"
}
}
- Setting up a Worker route:
resource "cloudflare_worker_route" "example" {
zone_id = var.cloudflare_zone_id
pattern = "example.com/api/*"
script_name = cloudflare_worker_script.example.name
}
resource "cloudflare_worker_script" "example" {
name = "api-worker"
content = file("${path.module}/worker.js")
}
Getting Started
- Install Terraform and set up your Cloudflare API credentials.
- Create a new Terraform configuration file (e.g.,
main.tf
) and add the Cloudflare provider:
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 3.0"
}
}
}
provider "cloudflare" {
api_token = var.cloudflare_api_token
}
- Define your Cloudflare resources using the provider's resource types.
- Run
terraform init
to initialize the working directory and download the provider. - Use
terraform plan
to preview changes andterraform apply
to apply them to your Cloudflare account.
Competitor Comparisons
The AWS Provider enables Terraform to manage AWS resources.
Pros of terraform-provider-aws
- Broader scope and more comprehensive coverage of AWS services
- Larger community and more frequent updates
- Better integration with other AWS-specific tools and services
Cons of terraform-provider-aws
- More complex and potentially overwhelming for users new to AWS
- Slower release cycle due to the extensive range of services covered
- May include unnecessary resources for users focused on specific AWS services
Code Comparison
terraform-provider-aws:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "Example Instance"
}
}
terraform-provider-cloudflare:
resource "cloudflare_record" "example" {
zone_id = "your_zone_id"
name = "example"
value = "203.0.113.10"
type = "A"
proxied = true
}
The AWS provider example creates an EC2 instance, while the Cloudflare provider example creates a DNS record. This reflects the different focus areas of each provider, with AWS covering a wide range of cloud services and Cloudflare specializing in DNS and CDN-related resources.
Terraform Provider for Google Cloud Platform
Pros of terraform-provider-google
- Broader ecosystem support with extensive GCP resource coverage
- More mature and established provider with a larger community
- Better integration with other Google Cloud services
Cons of terraform-provider-google
- More complex configuration due to the wide range of GCP resources
- Steeper learning curve for users new to GCP
- Potentially slower release cycles due to the larger codebase
Code Comparison
terraform-provider-google:
resource "google_compute_instance" "default" {
name = "test"
machine_type = "e2-medium"
zone = "us-central1-a"
}
terraform-provider-cloudflare:
resource "cloudflare_record" "example" {
zone_id = "example.com"
name = "test"
value = "203.0.113.10"
type = "A"
ttl = 3600
}
The Google provider example shows creating a compute instance, while the Cloudflare provider example demonstrates creating a DNS record. This highlights the different focus areas of each provider, with Google covering a broader range of cloud resources and Cloudflare specializing in DNS and edge services.
Terraform provider for Azure Resource Manager
Pros of terraform-provider-azurerm
- Broader scope: Covers the entire Azure ecosystem, offering more comprehensive cloud infrastructure management
- Deeper integration with Azure services: Provides access to a wider range of Azure-specific features and configurations
- More frequent updates: Generally receives more regular updates and feature additions due to Azure's rapid development
Cons of terraform-provider-azurerm
- Higher complexity: Managing Azure resources often requires more configuration and understanding of the Azure ecosystem
- Steeper learning curve: Due to the breadth of Azure services, it may take longer to become proficient with this provider
- Potentially slower performance: Managing a larger set of resources across Azure can lead to longer apply times in some cases
Code Comparison
terraform-provider-azurerm:
resource "azurerm_virtual_network" "example" {
name = "example-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
terraform-provider-cloudflare:
resource "cloudflare_record" "example" {
zone_id = var.cloudflare_zone_id
name = "example"
value = "203.0.113.10"
type = "A"
proxied = true
}
The Azure provider example shows creating a virtual network, demonstrating its focus on cloud infrastructure. The Cloudflare provider example shows creating a DNS record, highlighting its emphasis on edge network and DNS management.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Cloudflare Terraform Provider
Requirements
Terraform 1.2 or newer. We recommend running the latest version for optimal compatibility with the Cloudflare provider. Terraform versions older than 1.2 have known issues with newer features and internals.
Documentation
Full, comprehensive documentation is available on the Terraform Registry. API documentation and Developer documentation is also available for non-Terraform or service specific information.
Usage
# Declare the provider and version
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
version = "~> 5.0.0"
}
}
}
# Initialize the provider
provider "cloudflare" {
api_token = "Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY" # or set CLOUDFLARE_API_TOKEN env variable
}
# Configure a resource
resource "cloudflare_zone" "example_zone" {
account = {
id = "023e105f4ecef8ad9ca31a8372d0c353"
}
name = "example.com"
type = "full"
}
Initialize your project by running terraform init
in the directory.
Migrating to Terraform from using the Dashboard
Do you have an existing Cloudflare account (or many!) that you'd like to transition to be managed via Terraform? Check out cf-terraforming which is a tool Cloudflare has built to help dump the existing resources and import them into Terraform.
Maintenance
This SDK is actively maintained, however, many issues are tracked outside of GitHub on internal Cloudflare systems. Members of the community are welcome to join and discuss your issues during our weekly triage meetings. For urgent issues, please contact Cloudflare support.
Top Related Projects
The AWS Provider enables Terraform to manage AWS resources.
Terraform Provider for Google Cloud Platform
Terraform provider for Azure Resource Manager
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot