|
| 1 | +# Cloudflare DNS Module |
| 2 | + |
| 3 | +This Terraform module manages a zone and multiple records in Cloudflare. |
| 4 | +The module also simplifies a few boilerplate records at the apex for security purposes. |
| 5 | + |
| 6 | +<!-- BEGIN_TF_DOCS --> |
| 7 | +## Requirements |
| 8 | + |
| 9 | +| Name | Version | |
| 10 | +|------|---------| |
| 11 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3 | |
| 12 | +| <a name="requirement_cloudflare"></a> [cloudflare](#requirement\_cloudflare) | >= 4.39.0 | |
| 13 | + |
| 14 | +## Providers |
| 15 | + |
| 16 | +| Name | Version | |
| 17 | +|------|---------| |
| 18 | +| <a name="provider_cloudflare"></a> [cloudflare](#provider\_cloudflare) | >= 4.39.0 | |
| 19 | + |
| 20 | +## Resources |
| 21 | + |
| 22 | +| Name | Type | |
| 23 | +|------|------| |
| 24 | +| [cloudflare_record.apex_txt](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record) | resource | |
| 25 | +| [cloudflare_record.caa](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record) | resource | |
| 26 | +| [cloudflare_record.dns](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record) | resource | |
| 27 | +| [cloudflare_zone.dns](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/zone) | resource | |
| 28 | +| [cloudflare_zones.lookup](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/zones) | data source | |
| 29 | + |
| 30 | +## Inputs |
| 31 | + |
| 32 | +| Name | Description | Type | Default | Required | |
| 33 | +|------|-------------|------|---------|:--------:| |
| 34 | +| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | The ID of the Cloudflare account. | `string` | n/a | yes | |
| 35 | +| <a name="input_apex_txt"></a> [apex\_txt](#input\_apex\_txt) | List of TXT records to be added at the apex. | `list(string)` | `[]` | no | |
| 36 | +| <a name="input_caa_issuers"></a> [caa\_issuers](#input\_caa\_issuers) | List of CAs that can issue certificates. | `list(string)` | <pre>[<br/> "letsencrypt.org"<br/>]</pre> | no | |
| 37 | +| <a name="input_create_zone"></a> [create\_zone](#input\_create\_zone) | Whether to create the zone. Defaults to `true`. | `bool` | `true` | no | |
| 38 | +| <a name="input_default_ttl"></a> [default\_ttl](#input\_default\_ttl) | Default TTL for DNS records. Defaults to 1, which means “automatic”. | `number` | `1` | no | |
| 39 | +| <a name="input_domain"></a> [domain](#input\_domain) | The top-level domain name to hold the records. | `string` | n/a | yes | |
| 40 | +| <a name="input_records"></a> [records](#input\_records) | List of DNS records for the domain.<br/><br/> • `name` - (Optional) The name of the record. Defaults to "@" (i.e. an apex record).<br/> • `ttl` - (Optional) The TTL of the record. Defaults to `default_ttl`.<br/> • `type` - (Required) The record type.<br/> • `content` - (Required) The content of the record.<br/> • `priority` - (Optional) The priority of the record.<br/> • `proxied` - (Optional) Whether to use Cloudflare’s origin protection. Defaults to `false`. | <pre>map(object({<br/> name = optional(string, "@")<br/> ttl = optional(number)<br/> type = string<br/> content = string<br/> priority = optional(number)<br/> proxied = optional(bool, false)<br/> }))</pre> | n/a | yes | |
| 41 | +| <a name="input_security_contact"></a> [security\_contact](#input\_security\_contact) | Security contact for the domain. Defaults to 'security@DOMAIN', where `DOMAIN` is the top-level domain name. | `string` | `null` | no | |
| 42 | +| <a name="input_spf"></a> [spf](#input\_spf) | List of SPF directives for the domain. | `list(string)` | `[]` | no | |
| 43 | + |
| 44 | +## Outputs |
| 45 | + |
| 46 | +| Name | Description | |
| 47 | +|------|-------------| |
| 48 | +| <a name="output_zone_id"></a> [zone\_id](#output\_zone\_id) | The Zone ID. | |
| 49 | +<!-- END_TF_DOCS --> |
| 50 | + |
| 51 | +# Example Usage |
| 52 | + |
| 53 | +Below is a simple example for an example.com zone with a single subdomain record. |
| 54 | + |
| 55 | +```terraform |
| 56 | +module "example_com" { |
| 57 | + source = "github.com/answerdigital/terraform-modules//modules/cloudflare/dns?ref=v4" |
| 58 | +
|
| 59 | + domain = "example.com" |
| 60 | + records = { |
| 61 | + www = { |
| 62 | + name = "www" |
| 63 | + type = "A" |
| 64 | + value = "1.2.3.4" |
| 65 | + } |
| 66 | + } |
| 67 | + spf = [ |
| 68 | + "include:_spf.google.com" |
| 69 | + ] |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +By default, the module will create the zone as well as the records. If the zone |
| 74 | +was created elsewhere, set the `create_zone` flag to `false`. |
0 commit comments