main.tf 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. resource "aws_route53_resolver_endpoint" "private_resolver" {
  2. name = "xdr_forward_to_dns"
  3. direction = "OUTBOUND"
  4. security_group_ids = [aws_security_group.resolver_security_group.id]
  5. dynamic "ip_address" {
  6. for_each = var.subnets
  7. content {
  8. subnet_id = ip_address.value
  9. }
  10. }
  11. tags = merge(local.standard_tags, var.tags)
  12. }
  13. #----------------------------------------------------------------------------
  14. # DNS Resolver Security Group
  15. #----------------------------------------------------------------------------
  16. resource "aws_security_group" "resolver_security_group" {
  17. # checkov:skip=CKV2_AWS_5: this SG is attached to Private Resolver
  18. name = "route53_resolver_outbound"
  19. description = "Allow DNS inbound traffic"
  20. vpc_id = var.primary_vpc
  21. #----------------------------------------------------------------------------
  22. # INGRESS
  23. #----------------------------------------------------------------------------
  24. ingress {
  25. description = "DNS_UDP - Inbound"
  26. from_port = 53
  27. to_port = 53
  28. protocol = "udp"
  29. cidr_blocks = ["10.0.0.0/8"]
  30. }
  31. ingress {
  32. description = "DNS_TCP - Inbound"
  33. from_port = 53
  34. to_port = 53
  35. protocol = "tcp"
  36. cidr_blocks = ["10.0.0.0/8"]
  37. }
  38. #----------------------------------------------------------------------------
  39. # EGRESS
  40. #----------------------------------------------------------------------------
  41. egress {
  42. description = "DNS_UDP - Outbound"
  43. from_port = 53
  44. to_port = 53
  45. protocol = "udp"
  46. cidr_blocks = ["10.0.0.0/8"]
  47. }
  48. egress {
  49. description = "DNS_TCP - Outbound"
  50. from_port = 53
  51. to_port = 53
  52. protocol = "tcp"
  53. cidr_blocks = ["10.0.0.0/8"]
  54. }
  55. tags = merge(local.standard_tags, var.tags)
  56. }
  57. resource "aws_route53_resolver_rule" "private" {
  58. domain_name = var.dns_info["private"]["zone"]
  59. name = replace(var.dns_info["private"]["zone"], ".", "-")
  60. rule_type = "FORWARD"
  61. resolver_endpoint_id = aws_route53_resolver_endpoint.private_resolver.id
  62. dynamic "target_ip" {
  63. for_each = local.inbound_resolver_endpoints
  64. content {
  65. ip = target_ip.value
  66. }
  67. }
  68. tags = merge(local.standard_tags, var.tags)
  69. }
  70. resource "aws_route53_resolver_rule" "reverse" {
  71. domain_name = var.dns_info["reverse"]["zone"]
  72. name = replace(var.dns_info["reverse"]["zone"], ".", "-")
  73. rule_type = "FORWARD"
  74. resolver_endpoint_id = aws_route53_resolver_endpoint.private_resolver.id
  75. dynamic "target_ip" {
  76. for_each = local.inbound_resolver_endpoints
  77. content {
  78. ip = target_ip.value
  79. }
  80. }
  81. tags = merge(local.standard_tags, var.tags)
  82. }
  83. resource "aws_route53_resolver_rule_association" "private_association" {
  84. for_each = toset(var.additional_vpcs)
  85. resolver_rule_id = aws_route53_resolver_rule.private.id
  86. vpc_id = each.value
  87. }
  88. resource "aws_route53_resolver_rule_association" "reverse_association" {
  89. for_each = toset(var.additional_vpcs)
  90. resolver_rule_id = aws_route53_resolver_rule.reverse.id
  91. vpc_id = each.value
  92. }