nlb-for-hec.tf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # An NLB to allow for a static IP on the hec
  2. #########################
  3. # DNS Entry
  4. module "public_dns_record_hec_static" {
  5. source = "../../../submodules/dns/public_ALIAS_record"
  6. name = "${var.prefix}-hec"
  7. target_dns_name = aws_lb.hec_static.dns_name
  8. target_zone_id = aws_lb.hec_static.zone_id
  9. dns_info = var.dns_info
  10. providers = {
  11. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  12. }
  13. }
  14. #########################
  15. # EIP
  16. resource "aws_eip" "hec_static" {
  17. count = 2
  18. vpc = true
  19. lifecycle {
  20. prevent_destroy = true # Even if everything else goes away, we want to keep these.
  21. }
  22. tags = merge(local.standard_tags, var.tags, { "Name" : "${var.prefix}-hec-static" })
  23. }
  24. #########################
  25. # ELB
  26. resource "aws_lb" "hec_static" {
  27. name_prefix = substr("${var.prefix}-hec-static", 0, 6)
  28. load_balancer_type = "network"
  29. internal = false # tfsec:ignore:aws-elb-alb-not-public LB is intentionally public
  30. subnet_mapping {
  31. subnet_id = var.public_subnets[0]
  32. allocation_id = aws_eip.hec_static[0].id
  33. }
  34. subnet_mapping {
  35. subnet_id = var.public_subnets[1]
  36. allocation_id = aws_eip.hec_static[1].id
  37. }
  38. # Access logs are a feedback loop. They create logs that are then sent back through the HEC.
  39. # They should remain disabled.
  40. #access_logs {
  41. # bucket = "xdr-elb-${ var.environment }"
  42. # enabled = true
  43. #}
  44. tags = merge(local.standard_tags, var.tags, { "Name" : "${var.prefix}-hec-static" })
  45. }
  46. #resource "aws_lb_listener" "front_end" {
  47. # load_balancer_arn = aws_lb.front_end.arn
  48. # port = "443"
  49. # protocol = "TLS"
  50. # certificate_arn = "arn:aws:iam::187416307283:server-certificate/test_cert_rab3wuqwgja25ct3n4jdj2tzu4"
  51. # alpn_policy = "HTTP2Preferred"
  52. #
  53. # default_action {
  54. # type = "forward"
  55. # target_group_arn = aws_lb_target_group.front_end.arn
  56. # }
  57. #}
  58. resource "aws_lb_listener" "hec_static_443" {
  59. count = anytrue([local.is_moose, var.hec_listen_443]) ? 1 : 0
  60. load_balancer_arn = aws_lb.hec_static.arn
  61. port = 443
  62. protocol = "TCP"
  63. default_action {
  64. type = "forward"
  65. target_group_arn = aws_lb_target_group.hec_static_8088.arn
  66. }
  67. lifecycle {
  68. create_before_destroy = true
  69. }
  70. }
  71. resource "aws_lb_listener" "hec_static_8088" {
  72. load_balancer_arn = aws_lb.hec_static.arn
  73. port = 8088
  74. protocol = "TCP"
  75. default_action {
  76. type = "forward"
  77. target_group_arn = aws_lb_target_group.hec_static_8088.arn
  78. }
  79. lifecycle {
  80. create_before_destroy = true
  81. }
  82. }
  83. resource "aws_lb_target_group" "hec_static_8088" {
  84. name_prefix = substr("${var.prefix}-hec-static-targets", 0, 6)
  85. port = 8088
  86. protocol = "TCP"
  87. target_type = "alb"
  88. vpc_id = var.vpc_id
  89. health_check {
  90. port = 8088
  91. protocol = "HTTPS"
  92. path = "/services/collector/health/1.0"
  93. interval = "10"
  94. }
  95. lifecycle {
  96. create_before_destroy = true
  97. }
  98. tags = merge(local.standard_tags, var.tags, { "Name" : "${var.prefix}-hec-static" })
  99. }
  100. resource "aws_lb_target_group_attachment" "hec_static" {
  101. target_group_arn = aws_lb_target_group.hec_static_8088.arn
  102. target_id = aws_lb.hec.id
  103. port = 8088
  104. }