-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for all DNSimple record types and configurable default re…
…cords, including SRV (#12) This PR entirely overhauls the module's capability. It now supports: - All DNS record types supported by DNSimple - It allows for multiple records to be created as part of a single service definition by using index notation in the **service.meta** keys e.g. `meta.dnsimple_<attribute>[<index>]` or `meta.dnsimple_zone_name[1]`. This is due to a limitation of the meta section only supporting string values. - Variable expansion in the record name and content attributes so that developers can use any of the values defined in the service spec without hardcoding. Belongs to dnsimple/dnsimple-marketing#619 Belongs to https://github.com/dnsimple/dnsimple-external-integrations/issues/4
- Loading branch information
Showing
10 changed files
with
309 additions
and
50 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
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,57 @@ | ||
terraform { | ||
required_providers { | ||
dnsimple = { | ||
source = "dnsimple/dnsimple" | ||
version = ">= 1.0" | ||
} | ||
|
||
util = { | ||
source = "poseidon/util" | ||
version = "0.2.2" | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
zone_records_with_defaults = [ | ||
for record in var.zone_records : | ||
{ | ||
"zone_name" = record["zone_name"] == null ? var.defaults["zone_name"] : record["zone_name"], | ||
"record_name" = record["record_name"] | ||
"record_content" = record["record_content"], | ||
"record_type" = record["record_type"] == null ? var.defaults["record_type"] : record["record_type"], | ||
"record_ttl" = record["record_ttl"] == null ? var.defaults["record_ttl"] : record["record_ttl"], | ||
} | ||
] | ||
|
||
zone_records = { | ||
for record in local.zone_records_with_defaults : | ||
join("", [record["record_name"], record["record_type"], record["record_content"], record["zone_name"]]) => record | ||
} | ||
} | ||
|
||
data "util_replace" "record_names" { | ||
for_each = local.zone_records | ||
|
||
content = each.value["record_name"] | ||
replacements = { for match in regexall("\\$\\w+_?\\w+", each.value["record_name"]) : match => try(var.consul_service[replace(match, "$", "")], null) } | ||
} | ||
|
||
data "util_replace" "record_contents" { | ||
for_each = local.zone_records | ||
|
||
content = each.value["record_content"] | ||
replacements = { for match in regexall("\\$\\w+_?\\w+", each.value["record_content"]) : match => try(var.consul_service[replace(match, "$", "")], null) } | ||
} | ||
|
||
resource "dnsimple_zone_record" "consul_service_records" { | ||
for_each = local.zone_records | ||
|
||
zone_name = each.value.zone_name | ||
|
||
name = data.util_replace.record_names[each.key].replaced | ||
value = data.util_replace.record_contents[each.key].replaced | ||
|
||
type = each.value.record_type | ||
ttl = each.value.record_ttl | ||
} |
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 @@ | ||
output "defaults" { | ||
value = var.defaults | ||
} | ||
|
||
output "service_record_map" { | ||
value = [ | ||
for record in dnsimple_zone_record.consul_service_records : | ||
"${record.zone_name}:${record.name}:${record.type}:${record.ttl}:${record.value}" | ||
] | ||
} |
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,42 @@ | ||
variable "zone_records" { | ||
type = list(object({ | ||
zone_name = optional(string) | ||
record_name = string | ||
record_content = string | ||
record_type = optional(string) | ||
record_ttl = optional(number) | ||
})) | ||
} | ||
|
||
variable "consul_service" { | ||
type = object({ | ||
id = string | ||
name = string | ||
address = string | ||
port = number | ||
meta = map(string) | ||
tags = list(string) | ||
namespace = string | ||
status = string | ||
|
||
node = string | ||
node_id = string | ||
node_address = string | ||
node_datacenter = string | ||
node_tagged_addresses = map(string) | ||
node_meta = map(string) | ||
}) | ||
|
||
} | ||
|
||
variable "defaults" { | ||
type = object({ | ||
zone_name = optional(string) | ||
record_type = optional(string) | ||
record_ttl = optional(number) | ||
}) | ||
default = { | ||
record_ttl = 3600 | ||
record_type = "A" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
output "service_map" { | ||
value = [for id, s in local.consul_services : | ||
"${id}:${s.record_name}.${s.zone_name}:A:${s.record_ttl}:${s.address}" | ||
] | ||
output "service_records" { | ||
value = module.service_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
Oops, something went wrong.