Skip to content

tcarrondo/terraform-cloudflare-zone

Repository files navigation

cloudflare-zone

A Terraform module to create a domain zone in Cloudflare and add DNS the simpleway. It creates:

  • Zone;
  • Zone settings;
  • Naked A record, if provided;
  • Naked AAAA record, if provided;
  • WWW CNAME to naked;
  • all additional records provided.

Usage

provider "cloudflare" {
  email   = ""
  api_key = ""
  version = "~> 4"
}

module "domain_com" {
  source  = "tcarrondo/zone/cloudflare"
  version = "~> 4"

  domain = "domain.com"

  ipv4 = ["1.2.3.4"]
  ipv6 = ["2607:f0d0:1002:51::4"]

  records = [
    {
      name    = "mail"
      value   = "1.2.3.4"
    },
    {
      name     = "${module.domain_com.domain}"
      value    = "mail.${module.domain_com.domain}"
      type     = "MX"
      priority = "10"
      proxied  = false
    }
  ]
}

Requirements

Name Version
terraform ~> 1
cloudflare ~> 4

Providers

Name Version
cloudflare ~> 4

Modules

No modules.

Resources

Name Type
cloudflare_record.domain_ipv4 resource
cloudflare_record.domain_ipv6 resource
cloudflare_record.domain_www resource
cloudflare_record.records resource
cloudflare_zone.domain resource
cloudflare_zone_settings_override.domain resource
cloudflare_accounts.main data source

Inputs

Name Description Type Default Required
account_name Cloudflare account name where the resources will be created. If not specified will use the first account, so it is recommended to be specified when your user has access to more then one account. string "" no
domain Zone domain name string n/a yes
ipv4 Naked ipv4 (A) record value list(string) [] no
ipv6 Naked ipv6 (AAAA) record value list(string) [] no
plan Plan associated with the zone string "free" no
records Other (A, CNAME, MX, TXT) records list(map(any)) [] no
www_cname Custom www CNAME record value string "" no
zone_on Zone creation bool true no

Outputs

Name Description
domain Zone domain name
ns Zone nameservers
zone_id Zone ID