Skip to content

zoro16/terraform-cloudflare-records

Repository files navigation

Description

Terraform module to create/update Cloudflare DNS Records.

Usage

provider "cloudflare" {
  api_token = var.cloudflare_api_token
}

data "cloudflare_zone" "this" {
  name = "example.com"
}

module "records" {
  source = "../../"

  records = [
    {
      name    = "mail"
      proxied = false
      ttl     = 60
      type    = "A"
      value   = "10.10.10.10"
      zone_id = data.cloudflare_zone.this.id
    },
    {
      name    = "_25._tcp.mail"
      proxied = false
      ttl     = 60
      type    = "TLSA"
      zone_id = data.cloudflare_zone.this.id
      data = {
        certificate   = "T8kKkgeLqC5pi5tVfUN0Nf3vJMzb6NDAB4IBwrOHKunmCSNLHqYgrGnCUAN9SulQ"
        matching_type = 1
        selector      = 1
        usage         = 3
      }
    },
  ]
}

Requirements

Name Version
terraform >= 0.13.1
cloudflare >= 3.16.0

Providers

Name Version
cloudflare >= 3.16.0

Modules

No modules.

Resources

Name Type
cloudflare_record.this resource

Inputs

Name Description Type Default Required
records List of Maps of the records.

name
The name of the record.
Modifying this attribute will force creation of a new resource.

type
The type of the record. Available values: [A, AAAA, CAA, CNAME, TXT, SRV, LOC, MX, NS,
SPF, CERT, DNSKEY, DS, NAPTR, SMIMEA, SSHFP, TLSA, URI, PTR, HTTPS, SVCB].
Modifying this attribute will force creation of a new resource.

zone_id
The zone identifier to target for the resource.
Modifying this attribute will force creation of a new resource.

allow_overwrite
Allow creation of this record in Terraform to overwrite an existing record, if any.
This does not affect the ability to update the record in Terraform and does not prevent
other resources within Terraform or manual changes outside Terraform from overwriting this record.
This configuration is not recommended for most environments. Defaults to false.

comment
Comments or notes about the DNS record. This field has no effect on DNS responses.

priority
The priority of the record.

proxied
Whether the record gets Cloudflare's origin protection.

tags
Custom tags for the DNS record.

ttl
The TTL of the record.

value
The value of the record. Conflicts with data.

timeouts
(Block, Optional) The Timeout settings.

data
(Block List, Max: 1) Map of attributes that constitute the record value. Conflicts with value.
list(object({
name = string
value = optional(string)
type = string
ttl = number
proxied = bool
zone_id = string
allow_overwrite = optional(bool)
priority = optional(number)

tags = optional(set(string))
comment = optional(string)

data = optional(object({
algorithm = optional(number)
altitude = optional(number)
certificate = optional(string)
content = optional(string)
digest = optional(string)
digest_type = optional(number)
fingerprint = optional(string)
flags = optional(string)
key_tag = optional(number)
lat_degrees = optional(number)
lat_direction = optional(string)
lat_minutes = optional(number)
lat_seconds = optional(number)
long_degrees = optional(number)
long_direction = optional(string)
long_minutes = optional(number)
long_seconds = optional(number)
matching_type = optional(number)
name = optional(string)
order = optional(number)
port = optional(number)
precision_horz = optional(number)
precision_vert = optional(number)
preference = optional(number)
priority = optional(number)
proto = optional(string)
protocol = optional(number)
public_key = optional(string)
regex = optional(string)
replacement = optional(string)
selector = optional(number)
service = optional(string)
size = optional(number)
tag = optional(string)
target = optional(string)
type = optional(number)
usage = optional(number)
value = optional(string)
weight = optional(number)
}))

timeouts = optional(object({
create = optional(string)
update = optional(string)
}))
}))
[
{
"allow_overwrite": null,
"comment": null,
"data": null,
"name": null,
"priority": null,
"proxied": null,
"tags": null,
"timeouts": null,
"ttl": null,
"type": null,
"value": null,
"zone_id": null
}
]
no

Outputs

Name Description
records Records output:

* created_on (String) The RFC3339 timestamp of when the record was created.
* hostname (String) The FQDN of the record.
* id (String) The ID of this resource.
* metadata (Map of String) A key-value map of string metadata Cloudflare associates with the record.
** auto_added (Boolean)
** managed_by_apps (Boolean)
** managed_by_argo_tunnel (Boolean)
** source (String)

* modified_on (String) The RFC3339 timestamp of when the record was last modified.
* proxiable (Boolean) Shows whether this record can be proxied.