main.tf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. locals {
  2. # I decided to get fancy here. For the list of domains, if any are parents of the others, I create the associated NS records
  3. # to delegate it.
  4. # Grabs the parent domains
  5. parent_domains_all = { for domain in var.hosted_public_dns_zones: domain => regex("^[^\\.]*\\.(.+)$", domain)[0] }
  6. # filters out those that aren't in our list
  7. domains_with_parents = {
  8. for domain, parent in local.parent_domains_all:
  9. domain => parent if contains(var.hosted_public_dns_zones, parent)
  10. }
  11. # delegated parent domains
  12. delegated_parent_domains_all = { for domain, value in var.delegated_public_dns_zones: domain => regex("^[^\\.]*\\.(.+)$", domain)[0] }
  13. # filters out those that aren't in our list
  14. delegated_domain_parents = {
  15. for domain, parent in local.delegated_parent_domains_all:
  16. domain => parent if contains(var.hosted_public_dns_zones, parent)
  17. }
  18. }
  19. # These outputs are useful for debugging, but commenting them out for now.
  20. #output parent_domains {
  21. # value = local.parent_domains_all
  22. #}
  23. #output domains_with_parents {
  24. # value = local.domains_with_parents
  25. #}
  26. #output delegated_parent_domains {
  27. # value = local.delegated_parent_domains_all
  28. #}
  29. #output delegated_domain_parents {
  30. # value = local.delegated_domain_parents
  31. #}
  32. # Create the public zones
  33. resource "aws_route53_zone" "public" {
  34. for_each = toset(var.hosted_public_dns_zones)
  35. name = each.value
  36. tags = merge(var.standard_tags, var.tags)
  37. }
  38. #output "domains" {
  39. # value = aws_route53_zone.public
  40. #}
  41. resource "aws_route53_record" "soa" {
  42. for_each = local.domains_with_parents
  43. allow_overwrite = true
  44. name = each.key
  45. ttl = 60
  46. type = "NS"
  47. zone_id = aws_route53_zone.public[each.value].id
  48. records = aws_route53_zone.public[each.key].name_servers
  49. }
  50. # At this point, I don't know where to point these websites, so these are dummy addresses. But the below is
  51. # tested and functional when we have a web presence.
  52. #resource "aws_route53_record" "at" {
  53. # for_each = toset(var.hosted_public_dns_zones)
  54. # zone_id = aws_route53_zone.public[each.value].id
  55. # name = ""
  56. # type = "A"
  57. # ttl = "300"
  58. # records = [ "1.1.1.1" ]
  59. #}
  60. #
  61. #resource "aws_route53_record" "www" {
  62. # for_each = toset(var.hosted_public_dns_zones)
  63. # zone_id = aws_route53_zone.public[each.value].id
  64. # name = "www"
  65. # type = "CNAME"
  66. # ttl = "300"
  67. # records = [ each.value ]
  68. #}
  69. # Create delegations for domains hosted in other accounts
  70. resource "aws_route53_record" "soa_for_delegated" {
  71. for_each = var.delegated_public_dns_zones
  72. allow_overwrite = true
  73. name = each.key
  74. ttl = 60
  75. type = "NS"
  76. zone_id = aws_route53_zone.public[local.delegated_domain_parents[each.key]].id
  77. records = each.value
  78. }
  79. resource "aws_route53_record" "dnstest" {
  80. for_each = toset(var.hosted_public_dns_zones)
  81. zone_id = aws_route53_zone.public[each.value].id
  82. name = "dnstest"
  83. type = "A"
  84. ttl = "300"
  85. # Non-routable Test IP: https://tools.ietf.org/html/rfc5737
  86. records = [ "203.0.113.1" ]
  87. }