elb-without-ack.tf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 # tfsec:ignore:aws-elb-alb-not-public ELB is intentionally public
  43. drop_invalid_header_fields = true
  44. # Access logs are a feedback loop. They create logs that are then sent back through the HEC.
  45. # They should remain disabled.
  46. #access_logs {
  47. # bucket = "xdr-elb-${ var.environment }"
  48. # enabled = true
  49. #}
  50. }
  51. resource "aws_lb_listener" "hec_443" {
  52. count = anytrue([local.is_moose, var.hec_listen_443]) ? 1 : 0
  53. load_balancer_arn = aws_lb.hec.arn
  54. port = 443
  55. protocol = "HTTPS"
  56. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  57. certificate_arn = aws_acm_certificate.hec_cert.arn
  58. default_action {
  59. type = "forward"
  60. target_group_arn = aws_lb_target_group.hec_8088.arn
  61. }
  62. }
  63. resource "aws_lb_listener" "hec_8088" {
  64. load_balancer_arn = aws_lb.hec.arn
  65. port = 8088
  66. protocol = "HTTPS"
  67. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  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_target_group" "hec_8088" {
  75. name = "${var.prefix}-hec-targets"
  76. port = 8088
  77. protocol = "HTTPS"
  78. target_type = "instance"
  79. vpc_id = var.vpc_id
  80. health_check {
  81. path = "/services/collector/health/1.0"
  82. protocol = "HTTPS"
  83. }
  84. }
  85. # Attach the instnaces to the ELB
  86. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  87. for_each = toset([module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0]])
  88. lb_target_group_arn = aws_lb_target_group.hec_8088.arn
  89. autoscaling_group_name = each.key
  90. }