Terraform module that manages Cloudflare zones, DNS records, optional Argo Smart Routing, Tiered Caching, and Rulesets.
This module supports:
- Creating or using an existing Cloudflare zone.
- Managing multiple DNS records, including:
- Full control over TTL, proxying, priority, and comments.
- Enabling and configuring Cloudflare Argo features:
- Smart Routing
- Tiered Caching
- Defining custom Cloudflare Rulesets (e.g., redirect logic, access policies).
module "zone" {
source = "rashedobaid/zone/cloudflare"
# Required Cloudflare account ID
account_id = "your-cloudflare-account-id"
# Domain name to create/manage in Cloudflare
zone = "example.com"
# Whether to create a new zone or use an existing one
zone_enabled = true
# Enable Argo features
argo_enabled = true
argo_smart_routing_enabled = true
argo_tiered_caching_enabled = true
# DNS records to manage
records = [
{
name = "www"
type = "A"
content = "192.0.2.1"
ttl = 300
proxied = true
comment = "Main website"
},
{
name = "@"
type = "MX"
content = "mail.example.com"
ttl = 3600
priority = 10
comment = "Mail server"
}
]
# Optional rulesets to apply
rulesets = [
{
phase = "http_request_dynamic_redirect"
rules = [
{
description = "Redirect example.com to example.net"
expression = "http.host eq \"example.com\""
action = "redirect"
action_parameters = {
from_value = {
target_url = {
value = "https://example.net"
}
status_code = 301
preserve_query_string = true
}
}
}
]
}
]
}| Name | Version |
|---|---|
| cloudflare | >= 5.5.0 |
| Name | Version |
|---|---|
| cloudflare | >= 5.5.0 |
No modules.
| Name | Type |
|---|---|
| cloudflare_argo_smart_routing.default | resource |
| cloudflare_argo_tiered_caching.default | resource |
| cloudflare_dns_record.default | resource |
| cloudflare_ruleset.default | resource |
| cloudflare_zone.default | resource |
| cloudflare_zones.default | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| account_id | The Cloudflare account ID associated with the zone. | string |
n/a | yes |
| argo_enabled | Whether to enable Cloudflare Argo for the zone. | bool |
false |
no |
| argo_smart_routing_enabled | Enable smart routing as part of Argo features. | bool |
true |
no |
| argo_tiered_caching_enabled | Enable tiered caching as part of Argo features. | bool |
true |
no |
| records | List of DNS records to be created within the zone. | list(object({ |
[] |
no |
| rulesets | List of Rulesets to be created within the zone. | list(object({ |
[] |
no |
| type | Type of zone: 'full' for Cloudflare-managed DNS, or 'partial' for CNAME setup. | string |
"full" |
no |
| zone | The domain name of the Cloudflare zone (e.g., example.com). | string |
n/a | yes |
| zone_enabled | Determines whether to create a new DNS zone. If set to false, uses an existing zone. | bool |
true |
no |
| Name | Description |
|---|---|
| id | The unique identifier of the Cloudflare zone. |
| meta_phishing_detected | Indicates whether phishing content has been detected on the zone. |
| name_servers | List of Cloudflare-assigned name servers. Only populated for zones using full DNS setup. |
| record_key_to_id | Map of record keys (name-type-content) to record IDs. |
| ruleset_ids | Map of ruleset phases to their corresponding IDs. |
| status | Current status of the zone (e.g., 'active', 'pending'). |
| type | The zone type, indicating the plan or configuration applied (e.g., 'full' or 'partial'). |
| vanity_name_servers | List of custom vanity name servers assigned to the zone, if configured. |
| verification_key | TXT record value used to verify domain ownership. Applicable only for zones of type 'partial'. |
Module is maintained by Rashed Obaid.
Apache 2 Licensed. See LICENSE for full details.