elb-without-ack.tf 3.2 KB

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