elb-without-ack.tf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #------------------------------------------------------------------------------
  2. # An external ALB for the indexers for HEC
  3. #------------------------------------------------------------------------------
  4. #########################
  5. # DNS Entry
  6. module "public_dns_record_hec" {
  7. source = "../../../submodules/dns/public_ALIAS_record"
  8. name = "${var.prefix}-hec"
  9. target_dns_name = aws_lb.hec.dns_name
  10. target_zone_id = aws_lb.hec.zone_id
  11. dns_info = var.dns_info
  12. providers = {
  13. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  14. }
  15. }
  16. #########################
  17. # Certificate
  18. resource "aws_acm_certificate" "hec_cert" {
  19. domain_name = "${var.prefix}-hec.${var.dns_info["public"]["zone"]}"
  20. validation_method = "DNS"
  21. lifecycle {
  22. create_before_destroy = true
  23. }
  24. tags = merge(var.standard_tags, var.tags)
  25. }
  26. resource "aws_acm_certificate_validation" "hec_cert_validation" {
  27. certificate_arn = aws_acm_certificate.hec_cert.arn
  28. validation_record_fqdns = [for record in aws_route53_record.hec_cert_validation: record.fqdn]
  29. }
  30. resource "aws_route53_record" "hec_cert_validation" {
  31. provider = aws.mdr-common-services-commercial
  32. for_each = {
  33. for dvo in aws_acm_certificate.hec_cert.domain_validation_options : dvo.domain_name => {
  34. name = dvo.resource_record_name
  35. record = dvo.resource_record_value
  36. type = dvo.resource_record_type
  37. }
  38. }
  39. allow_overwrite = true
  40. name = each.value.name
  41. records = [each.value.record]
  42. ttl = 60
  43. type = each.value.type
  44. zone_id = var.dns_info["public"]["zone_id"]
  45. }
  46. #########################
  47. # ELB
  48. resource "aws_lb" "hec" {
  49. tags = merge(var.standard_tags, var.tags)
  50. name = "${var.prefix}-hec"
  51. load_balancer_type = "application"
  52. security_groups = [ aws_security_group.hec_elb_security_group.id ]
  53. subnets = var.public_subnets
  54. internal = false
  55. # Access logs are a feedback loop. They create logs that are then sent back through the HEC.
  56. # They should remain disabled.
  57. #access_logs {
  58. # bucket = "xdr-elb-${ var.environment }"
  59. # enabled = true
  60. #}
  61. }
  62. resource "aws_lb_listener" "hec_443" {
  63. count = anytrue([ local.is_moose, var.hec_listen_443 ]) ? 1 : 0
  64. load_balancer_arn = aws_lb.hec.arn
  65. port = 443
  66. protocol = "HTTPS"
  67. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  68. certificate_arn = aws_acm_certificate.hec_cert.arn
  69. default_action {
  70. type = "forward"
  71. target_group_arn = aws_lb_target_group.hec_8088.arn
  72. }
  73. }
  74. resource "aws_lb_listener" "hec_8088" {
  75. load_balancer_arn = aws_lb.hec.arn
  76. port = 8088
  77. protocol = "HTTPS"
  78. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  79. certificate_arn = aws_acm_certificate.hec_cert.arn
  80. default_action {
  81. type = "forward"
  82. target_group_arn = aws_lb_target_group.hec_8088.arn
  83. }
  84. }
  85. resource "aws_lb_target_group" "hec_8088" {
  86. name = "${var.prefix}-hec-targets"
  87. port = 8088
  88. protocol = "HTTPS"
  89. target_type = "instance"
  90. vpc_id = var.vpc_id
  91. health_check {
  92. path = "/services/collector/health/1.0"
  93. protocol = "HTTPS"
  94. }
  95. }
  96. # Attach the instnaces to the ELB
  97. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  98. for_each = toset([ module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0] ])
  99. alb_target_group_arn = aws_lb_target_group.hec_8088.arn
  100. autoscaling_group_name = each.key
  101. }