This Terraform module manages Cloudflare DNS zones and records. It provides functionality to both create new DNS zones and manage records within existing zones using one YAML file. The module is published in both Terraform and OpenTofu registries.
- Create new Cloudflare DNS zones
- Manage existing Cloudflare DNS zones
- Create and manage DNS records of various types
- Supports multiple DNS records across different zones
module "cloudflare_dns" {
source = "langburd/dns-zone/cloudflare"
version = "~> 1.0"
# Path to your YAML configuration file
zones_file = "./zones.yaml"
}
Example of zones.yaml
(filename could be arbitrary):
---
# zones.yaml
dns_zones:
- name: some-example-domain.com
create: true
default_ttl: 3600
records:
A:
- name: '@'
content: 5.6.7.8
- name: ftp
comment: 'FTP server'
content: 1.2.3.4
ttl: 600
CNAME:
- name: www
content: some-example-domain.com
proxied: true
ttl: 1
- name: mail
content: ghs.googlehosted.com
MX:
- name: '@'
content: aspmx.l.google.com
priority: 10
- name: '@'
content: alt1.aspmx.l.google.com
priority: 20
TXT:
- name: '@'
comment: 'Google site verification'
content: v=spf1 include:_spf.google.com ~all
- name: '@'
comment: 'Azure domain verification'
content: MS=ms18454532
Name | Version |
---|---|
terraform | >= 1.2.0 |
cloudflare | >= 4.0, < 5.0 |
Name | Version |
---|---|
cloudflare | >= 4.0, < 5.0 |
No modules.
Name | Type |
---|---|
cloudflare_record.dns_records | resource |
cloudflare_zone.created_zones | resource |
cloudflare_accounts.current | data source |
cloudflare_zone.existing_zones | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
zones_file | Path to the YAML file containing DNS zones and records. | string |
n/a | yes |
Name | Description |
---|---|
created_zones | Cloudflare DNS zones. |
dns_records | Cloudflare DNS records. |
existing_zones | Cloudflare DNS zones. |
- The module automatically handles TXT record content formatting by adding required quotes
- Zone IDs are automatically looked up and managed internally
- Record names are automatically formatted to ensure uniqueness
Contributions are welcome! This project uses pre-commit hooks to ensure code quality. Please make sure to install and run pre-commit before submitting any changes.
MIT License
Complete license is available in the LICENSE
file.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
All other trademarks referenced herein are the property of their respective owners.
Copyright © 2024-2025 Avi Langburd