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.
Full, comprehensive documentation is available on the Terraform Registry. API documentation and Developer documentation is also available for non-Terraform or service specific information.
# 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.
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.