-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add simple records * Move iteration over records to locals * Fix fmt * Add collection submodule * Use collection submodule for the same name/type * Add examples
- Loading branch information
Showing
17 changed files
with
397 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "cloudflare_zone" "this" { | ||
name = var.domain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Example | ||
|
||
This example will create multiple DNS records. | ||
|
||
Output for `example.com`: | ||
|
||
```hcl | ||
records = { | ||
"A_mytestdomain.example.com" = { | ||
"4.4.4.4" = { | ||
"created" = "2021-11-26T15:36:09.973899Z" | ||
"id" = "90bc69d4b5e5bb5c7a58858d7156cf36" | ||
} | ||
"8.8.8.8" = { | ||
"created" = "2021-11-26T15:36:09.764104Z" | ||
"id" = "03aae5145060e77dfc903e4a41ad7f4d" | ||
} | ||
} | ||
"CNAME_myproxieddomain.example.com" = { | ||
"example.com" = { | ||
"created" = "2021-11-26T15:36:10.544251Z" | ||
"id" = "20cfad416b4dcd3fdbb16d3d8e7ce2d3" | ||
} | ||
} | ||
"MX_mymaildomain.example.com" = { | ||
"mail1.mx.maildomainexample.com" = { | ||
"created" = "2021-11-26T15:36:10.323258Z" | ||
"id" = "61cc65ae9845eeb5d0a253f03cac2acd" | ||
} | ||
"mail2.mx.maildomainexample.com" = { | ||
"created" = "2021-11-26T15:36:10.189034Z" | ||
"id" = "e16fd484fa77f12049af5e8c66958626" | ||
} | ||
} | ||
"NS_mynsdomain.example.com" = { | ||
"ns1.mytestdns.com" = { | ||
"created" = "2021-11-26T15:36:11.447047Z" | ||
"id" = "b2ba6ade689541d5afff586bdacbfd5f" | ||
} | ||
"ns2.mytestdns.com" = { | ||
"created" = "2021-11-26T15:36:11.126715Z" | ||
"id" = "8df957fd25f7a2212fcae8ba00cd6b39" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
No providers. | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_records"></a> [records](#module\_records) | ./../../ | n/a | | ||
|
||
## Resources | ||
|
||
No resources. | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_api_token"></a> [api\_token](#input\_api\_token) | The Cloudflare API token. | `string` | n/a | yes | | ||
| <a name="input_domain"></a> [domain](#input\_domain) | Cloudflare domain name to create | `string` | `"example.com"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_records"></a> [records](#output\_records) | Cloudflare Zone DNS Records | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
Copyright (c) 2021 **[Flaconi GmbH](https://github.com/flaconi)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
locals { | ||
records = [ | ||
{ | ||
name = "myproxieddomain" | ||
value = "example.com" | ||
type = "CNAME" | ||
ttl = 1 | ||
proxied = true | ||
priority = null | ||
}, | ||
{ | ||
name = "mytestdomain" | ||
value = "8.8.8.8" | ||
type = "A" | ||
ttl = 600 | ||
proxied = false | ||
priority = null | ||
}, | ||
{ | ||
name = "mytestdomain" | ||
value = "4.4.4.4" | ||
type = "A" | ||
ttl = 600 | ||
proxied = false | ||
priority = null | ||
}, | ||
{ | ||
name = "mymaildomain" | ||
value = "mail1.mx.maildomainexample.com" | ||
type = "MX" | ||
ttl = 300 | ||
proxied = false | ||
priority = 10 | ||
}, | ||
{ | ||
name = "mymaildomain" | ||
value = "mail2.mx.maildomainexample.com" | ||
type = "MX" | ||
ttl = 300 | ||
proxied = false | ||
priority = 20 | ||
}, | ||
{ | ||
name = "mynsdomain" | ||
value = "ns1.mytestdns.com" | ||
type = "NS" | ||
ttl = 300 | ||
proxied = false | ||
priority = null | ||
}, | ||
{ | ||
name = "mynsdomain" | ||
value = "ns2.mytestdns.com" | ||
type = "NS" | ||
ttl = 300 | ||
proxied = false | ||
priority = null | ||
}, | ||
] | ||
} | ||
|
||
module "records" { | ||
source = "./../../" | ||
api_token = var.api_token | ||
domain = var.domain | ||
records = local.records | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "records" { | ||
description = "Cloudflare Zone DNS Records" | ||
value = module.records.records | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
variable "api_token" { | ||
description = "The Cloudflare API token." | ||
type = string | ||
} | ||
|
||
variable "domain" { | ||
description = "Cloudflare domain name to create" | ||
type = string | ||
default = "example.com" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
locals { | ||
# Grouping records by type and name | ||
collections = { for r in var.records : "${r.type}_${r.name}.${var.domain}" => r... } | ||
} | ||
|
||
module "records" { | ||
source = "./modules/record_collection" | ||
for_each = local.collections | ||
|
||
zone_id = data.cloudflare_zone.this.id | ||
name = each.value[0].name | ||
type = each.value[0].type | ||
values = [for r in each.value : | ||
{ | ||
value = r.value | ||
ttl = r.ttl | ||
proxied = r.proxied | ||
priority = r.priority | ||
} | ||
] | ||
allow_overwrite = var.allow_overwrite | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Submodule record_collection | ||
|
||
Terraform submodule to create a list of Cloudflare DNS records grouped by type and name. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.0 | | ||
| <a name="requirement_cloudflare"></a> [cloudflare](#requirement\_cloudflare) | ~> 3.2 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_cloudflare"></a> [cloudflare](#provider\_cloudflare) | ~> 3.2 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [cloudflare_record.this](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | Cloudflare Hosted Zone ID | `string` | n/a | yes | | ||
| <a name="input_name"></a> [name](#input\_name) | Cloudflare Hosted Zone Record Name | `string` | n/a | yes | | ||
| <a name="input_type"></a> [type](#input\_type) | Cloudflare Hosted Zone Record Type | `string` | n/a | yes | | ||
| <a name="input_values"></a> [values](#input\_values) | List of values to create | <pre>list(object({<br> value = string<br> ttl = number<br> proxied = bool<br> priority = number<br> }))</pre> | `[]` | no | | ||
| <a name="input_allow_overwrite"></a> [allow\_overwrite](#input\_allow\_overwrite) | Allow override existing records | `bool` | `false` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_values"></a> [values](#output\_values) | Cloudflare Zone DNS Records | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
Copyright (c) 2021 **[Flaconi GmbH](https://github.com/flaconi)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resource "cloudflare_record" "this" { | ||
count = length(var.values) | ||
|
||
zone_id = var.zone_id | ||
type = var.type | ||
name = var.name | ||
value = var.values[count.index].value | ||
ttl = var.values[count.index].ttl | ||
proxied = var.values[count.index].proxied | ||
priority = var.values[count.index].priority | ||
|
||
allow_overwrite = var.allow_overwrite | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "values" { | ||
description = "Cloudflare Zone DNS Records" | ||
value = { for v in cloudflare_record.this : v.value => { id = v.id, created = v.created_on } } | ||
} |
Oops, something went wrong.