1 – Initialize Terraform
This tutorial shows you how to get started with Terraform. You just signed up your domain (example.com) on Cloudflare to manage everything in Terraform and now you will create a DNS record pointing www.example.com to a web server at 203.0.113.10.
Before you begin, ensure you have:
- Installed Terraform
- Created an API Token with permissions to edit resources for this tutorial
Create a file named main.tf, filling in your own values for the API token, zone ID, account ID, and domain:
terraform { required_providers { cloudflare = { source = "cloudflare/cloudflare" version = "~> 5" } }}
provider "cloudflare" { api_token = "<YOUR_API_TOKEN>"}
variable "zone_id" { default = "<YOUR_ZONE_ID>"}
variable "account_id" { default = "<YOUR_ACCOUNT_ID>"}
variable "domain" { default = "<YOUR_DOMAIN>"}
resource "cloudflare_dns_record" "www" { zone_id = "<YOUR_ZONE_ID>" name = "www" content = "203.0.113.10" type = "A" ttl = 1 proxied = true comment = "Domain verification record"}Initialize Terraform to download the Cloudflare provider:
terraform initReview what will be created:
terraform planTerraform used the selected providers to generate the following execution plan. Resource actions areindicated with the following symbols: + create
Terraform will perform the following actions:
# cloudflare_dns_record.www will be created + resource "cloudflare_dns_record" "www" { + comment = "Domain verification record" + comment_modified_on = (known after apply) + content = "203.0.113.10" + created_on = (known after apply) + id = (known after apply) + meta = (known after apply) + modified_on = (known after apply) + name = "www" + proxiable = (known after apply) + proxied = true + settings = (known after apply) + tags = (known after apply) + tags_modified_on = (known after apply) + ttl = 1 + type = "A" + zone_id = "<YOUR_ZONE_ID>" }
Plan: 1 to add, 0 to change, 0 to destroy.Apply your configuration:
terraform applyType yes when prompted.
Terraform used the selected providers to generate the following execution plan. Resource actions areindicated with the following symbols: + create
Terraform will perform the following actions:
# cloudflare_dns_record.www will be created + resource "cloudflare_dns_record" "www" { + comment = "Domain verification record" + comment_modified_on = (known after apply) + content = "203.0.113.10" + created_on = (known after apply) + id = (known after apply) + meta = (known after apply) + modified_on = (known after apply) + name = "www" + proxiable = (known after apply) + proxied = true + settings = (known after apply) + tags = (known after apply) + tags_modified_on = (known after apply) + ttl = 1 + type = "A" + zone_id = "<YOUR_ZONE_ID>" }
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.
Enter a value: yes
cloudflare_dns_record.www: Creating...cloudflare_dns_record.www: Creation complete after 0s
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.After creation, verify the DNS record:
dig www.example.comTest the web server response:
curl https://www.example.comHello, this is 203.0.113.10!To see the full results returned from the API call:
terraform showYou can also check the Cloudflare dashboard ↗ and go to DNS > Records.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark