Skip to content

langburd/terraform-cloudflare-dns-zone

Repository files navigation

Terraform Cloudflare DNS Zone Module

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.

Features

  • 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

Usage

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

Requirements

Name Version
terraform >= 1.2.0
cloudflare >= 4.0, < 5.0

Providers

Name Version
cloudflare >= 4.0, < 5.0

Modules

No modules.

Resources

Name Type
cloudflare_record.dns_records resource
cloudflare_zone.created_zones resource
cloudflare_accounts.current data source
cloudflare_zone.existing_zones data source

Inputs

Name Description Type Default Required
zones_file Path to the YAML file containing DNS zones and records. string n/a yes

Outputs

Name Description
created_zones Cloudflare DNS zones.
dns_records Cloudflare DNS records.
existing_zones Cloudflare DNS zones.

Notes

  • 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

Contributing

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.

License

MIT License

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.

Trademarks

All other trademarks referenced herein are the property of their respective owners.

Copyrights

Copyright © 2024-2025 Avi Langburd

About

Terraform module for managing CloudFlare DNS zones and their records from a YAML file

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages