-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50762c4
commit b3dc18f
Showing
9 changed files
with
410 additions
and
115 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.tf | ||
*-managed-zone/ |
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,41 @@ | ||
import logging | ||
from easyzone import easyzone | ||
from dns.rdatatype import _by_text as DNSRecordTypes | ||
|
||
|
||
class DNSRecordSet: | ||
""" | ||
a simple DNS record set representation | ||
""" | ||
|
||
def __init__(self, name: str, rectype: str, ttl: int, rrdatas: list[str]): | ||
self.name = name | ||
self.rectype = rectype | ||
self.ttl = ttl | ||
self.rrdatas = rrdatas | ||
|
||
@staticmethod | ||
def create_from_easyzone( | ||
name: easyzone.Name, records: easyzone.Records | ||
) -> "DNSRecordSet": | ||
""" | ||
create a simple DNS record from an easyzone record. | ||
""" | ||
rrdatas = records.items | ||
if len(rrdatas) > 0 and isinstance(rrdatas[0], (tuple, list)): | ||
rrdatas = list(map(lambda r: " ".join(map(lambda v: str(v), r)), rrdatas)) | ||
|
||
return DNSRecordSet(name.name, records.type, name.ttl, rrdatas) | ||
|
||
|
||
def create_from_zone(zone: easyzone.Zone) -> [DNSRecordSet]: | ||
result: [DNSRecordSet] = [] | ||
for key, name in zone.names.items(): | ||
for rectype in DNSRecordTypes.keys(): | ||
records = name.records(rectype) | ||
if not records: | ||
continue | ||
|
||
result.append(DNSRecordSet.create_from_easyzone(name, records)) | ||
|
||
return result |
27 changes: 27 additions & 0 deletions
27
src/zonefile_migrate/terraform-modules/google-managed-zone.tf
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,27 @@ | ||
variable domain_name { | ||
description = "domain name to create zone for" | ||
type = string | ||
} | ||
|
||
variable dns_record_sets { | ||
description = "DNS record sets in this domain" | ||
type = list(object({ | ||
name = string | ||
type = string | ||
ttl = number | ||
rrdatas = list(string) | ||
})) | ||
} | ||
resource "google_dns_managed_zone" "managed_zone" { | ||
name = replace(trimsuffix(var.domain_name, "."), "/\\./", "-") | ||
dns_name = var.domain_name | ||
} | ||
|
||
resource "google_dns_record_set" "record" { | ||
for_each = {for r in var.dns_record_sets: format("%s-%s", r.name, r.type) => r} | ||
name = each.value.name | ||
managed_zone = google_dns_managed_zone.managed_zone.name | ||
type = each.value.type | ||
ttl = each.value.ttl | ||
rrdatas = each.value.rrdatas | ||
} |
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.