The module consolidates the management of DNS records in an existing or new Cloudflare DNS zone. Records are supplied as input parameters of the module to keep their management in a single code block. Supported record types: A, AAAA, CNAME, MX, NS, TXT.

Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_cloudflare_dns" {
  source  = "solutions.corewide.com/cloudflare/tf-cloudflare-dns/cloudflare"
  version = "~> 2.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 2.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "2.0.0"

DNS in Cloudflare

DNS management in Cloudflare
€280
BUY
817
v2.0.0 released 2 months, 1 week ago
New version approx. every 9 weeks

The module consolidates the management of DNS records in an existing or new Cloudflare DNS zone. Records are supplied as input parameters of the module to keep their management in a single code block. Supported record types: A, AAAA, CNAME, MX, NS, TXT.

Minimal setup with a single record in an existing DNS zone:

 hclmodule "dns" {
  source  = "solutions.corewide.com/cloudflare/tf-cloudflare-dns/cloudflare"
  version = "~> 2.0"

  account_id = "1234567890a1234567890b1234567890"
  zone_name  = "example.com"

  records = {
    foo = {
      type    = "A"
      proxied = true
      value   = ["10.0.2.20"]
    }
  }
}

Custom configuration setup with a new DNS zone and multiple records with different configuration:

 hclmodule "dns" {
  source  = "solutions.corewide.com/cloudflare/tf-cloudflare-dns/cloudflare"
  version = "~> 2.0"

  zone_name   = "example.com"
  account_id  = "1234567890a1234567890b1234567890"
  create_zone = true

  records = {
    "@" = {
      type  = "A"
      value = ["10.0.1.10"]
      ttl   = 7200
    }
    "foo" = {
      type    = "A"
      value   = ["10.0.2.20"]
      proxied = true
    }
    "www" = {
      proxied = true
      type    = "CNAME"
      value   = ["example.com"]
    }
    "v6" = {
      type = "AAAA"
      ttl  = 500

      value = [
        "2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF",
        "2001:0000:130F:0000:0000:09C0:876A:130B",
      ]
    }
    "mail" = {
      type     = "MX"
      value    = ["example.com"]
      priority = 10
    }
  }
}
Variable Description Type Default Required Sensitive
account_id Cloudflare account ID to manage the zone resource string yes no
records[<key>] Name of the DNS record string yes no
zone_name The hosted DNS zone name to create records in string yes no
create_zone Enable hosted zone creation bool false no no
records DNS records configuration map(object) {} no no
records[<key>].priority The priority of the record (only for MX type) number 0 no no
records[<key>].proxied Whether the record gets Cloudflare's origin protection bool false no no
records[<key>].ttl The time to live of the record number 300 no no
records[<key>].type The type of the record. Possible values are: A, AAAA, CNAME, MX, NS and TXT string yes no
records[<key>].value The content of the record list(string) yes no
Output Description Type Sensitive
records DNS records resource attributes computed no
zone Hosted DNS zone attributes computed no
Dependency Version Kind
terraform >= 1.3 CLI
cloudflare/cloudflare ~> 5.0 provider

Not sure where to start?
Let's find your perfect match.