Selaa lähdekoodia

Creates Legacy DNS Entries

Module creates legacy DNS entries to aid in the transition. Not intended
for permanent use.

Also, adds the ability to disable DNS entries in the private/public DNS
submodules.

To be tagged v0.5.12
Fred Damstra 5 vuotta sitten
vanhempi
sitoutus
1f090f959d

+ 5 - 0
base/dns/legacy_dns_entries/README.md

@@ -0,0 +1,5 @@
+# Legacy DNS Entries
+
+Creates DNS entries from legacy services.
+
+Note! Not intended for long term use. When instances are moved over to TF12, they should create their own DNS records and be removed from here. To remove, simply comment out or delete the line in `env.hcl`.

+ 44 - 0
base/dns/legacy_dns_entries/main.tf

@@ -0,0 +1,44 @@
+# Sadly, this would be far easier if we could use for_each in a module. We can't, so we're cutting and pasting
+# code from submodules/dns/private_A_record
+locals {
+  # For reverse dns:
+  # 1) Split the ip addresses into 4 octets
+  private_octets = { for name, address in var.legacy_private_dns: name => regex("^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$", address) }
+  # 2) Reverse them, but only if the first octet is 10 (maybe handle 192.168 and 172.16 later), and if enabled
+  private_reverse_addresses = { for name, octets in local.private_octets: name => join(".", reverse(slice(octets, 1, 4))) if octets[0] == "10" }
+}
+
+# Private
+resource "aws_route53_record" "private" {
+  for_each = var.legacy_private_dns
+
+  name = each.key
+  type = "A"
+  ttl  = 300
+  zone_id = var.dns_info["private"]["zone_id"]
+  records = [ each.value ]
+  provider = aws.c2
+}
+
+# Reverse
+resource "aws_route53_record" "reverse_dns" {
+  for_each = local.private_reverse_addresses
+  name = each.value
+  type = "PTR"
+  ttl  = 300
+  zone_id = var.dns_info["reverse"]["zone_id"]
+  records = [ each.key ]
+  provider = aws.c2
+}
+
+# Public
+resource "aws_route53_record" "public" {
+  for_each = var.legacy_public_dns
+
+  name = each.key
+  type = "A"
+  ttl  = 300
+  zone_id = var.dns_info["public"]["zone_id"]
+  records = [ each.value ]
+  provider = aws.mdr-common-services-commercial
+}

+ 0 - 0
base/dns/legacy_dns_entries/outputs.tf


+ 18 - 0
base/dns/legacy_dns_entries/vars.tf

@@ -0,0 +1,18 @@
+variable legacy_private_dns { 
+  description = "A map of legacy hostnames to lists of IPs. To disable, just remove an entry."
+  type = map 
+}
+
+variable legacy_public_dns { 
+  description = "A map of legacy hostnames to lists of IPs. To disable, just remove an entry."
+  type = map 
+}
+
+# inherited variables
+variable tags { type = map }
+variable dns_servers { type = list }
+variable dns_info { type = map }
+variable standard_tags { type = map }
+variable aws_account_id { type = string }
+variable aws_partition { type = string }
+variable account_list { type = list }

+ 4 - 2
submodules/dns/private_A_record/main.tf

@@ -2,11 +2,13 @@ locals {
   # For reverse dns:
   # 1) Split the ip addresses into 4 octets
   octets = [ for ip in var.ip_addresses: regex("^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$", ip) ]
-  # 2) Reverse them, but only if the first octet is 10 (maybe handle 192.168 and 172.16 later)
-  reverse_addresses = [ for octets in local.octets: join(".", reverse(slice(octets, 1, 4))) if octets[0] == "10" ] 
+  # 2) Reverse them, but only if the first octet is 10 (maybe handle 192.168 and 172.16 later), and if enabled
+  reverse_addresses = [ for octets in local.octets: join(".", reverse(slice(octets, 1, 4))) if octets[0] == "10" && var.enabled == true ] 
 }
 
 resource "aws_route53_record" "dns" {
+  count = var.enabled ? 1 : 0
+
   name = var.name
   type = "A"
   ttl  = 300

+ 1 - 1
submodules/dns/private_A_record/outputs.tf

@@ -1,6 +1,6 @@
 output "forward" { 
   # Parenthesis required to resolve ambiguity
-  value = { (aws_route53_record.dns.fqdn) = aws_route53_record.dns.records }
+  value = { for entry in aws_route53_record.dns: entry.fqdn => entry.records }
 }
 
 output "reverse" {

+ 6 - 0
submodules/dns/private_A_record/vars.tf

@@ -1,3 +1,9 @@
+variable "enabled" { 
+  description = "Set to false to do nothing"
+  type = bool 
+  default = true
+}
+
 variable "name" { type = string }
 variable "ip_addresses" { type = list }
 variable "dns_info" { type = map }

+ 2 - 0
submodules/dns/public_A_record/main.tf

@@ -1,4 +1,6 @@
 resource "aws_route53_record" "dns" {
+  count = var.enabled ? 1 : 0
+
   name = var.name
   type = "A"
   ttl  = 300

+ 1 - 1
submodules/dns/public_A_record/outputs.tf

@@ -1,4 +1,4 @@
 output "forward" { 
   # Parenthesis required to resolve ambiguity
-  value = { (aws_route53_record.dns.fqdn) = aws_route53_record.dns.records }
+  value = { for entry in aws_route53_record.dns: entry.fqdn => entry.records }
 }

+ 6 - 0
submodules/dns/public_A_record/vars.tf

@@ -1,3 +1,9 @@
+variable "enabled" {
+  description = "Set to false to do nothing"
+  type = bool
+  default = true
+}
+
 variable "name" { type = string }
 variable "ip_addresses" { type = list }
 variable "dns_info" { type = map }