elb-hec.tf 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. resource "aws_lb" "alsi-alb-hec" {
  2. count = local.alsi_hec_alb ? 1 : 0
  3. name = "${var.prefix}-alsi-alb-hec"
  4. internal = false #tfsec:ignore:aws-elb-alb-not-public The ALB requires Internet exposure
  5. load_balancer_type = "application"
  6. drop_invalid_header_fields = true
  7. # Not supported for NLB
  8. security_groups = [aws_security_group.alsi-alb-hec-sg.id]
  9. # Note, changing subnets results in recreation of the resource
  10. subnets = var.subnets
  11. enable_cross_zone_load_balancing = true
  12. access_logs {
  13. bucket = "xdr-elb-${var.environment}"
  14. enabled = true
  15. }
  16. tags = merge(local.standard_tags, var.tags)
  17. }
  18. #########################
  19. # Listeners
  20. resource "aws_lb_listener" "alsi-alb-hec-listener-https" {
  21. count = local.alsi_hec_alb ? 1 : 0
  22. load_balancer_arn = aws_lb.alsi-alb-hec[count.index].arn
  23. port = "443"
  24. protocol = "HTTPS"
  25. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  26. certificate_arn = aws_acm_certificate.cert_hec[count.index].arn
  27. default_action {
  28. type = "forward"
  29. target_group_arn = aws_lb_target_group.alsi-alb-hec-target-8088[count.index].arn
  30. }
  31. }
  32. # Only alb's can redirect
  33. resource "aws_lb_listener" "alsi-alb-hec-listener-http" {
  34. count = local.alsi_hec_alb ? 1 : 0
  35. load_balancer_arn = aws_lb.alsi-alb-hec[count.index].arn
  36. port = "80"
  37. protocol = "HTTP"
  38. default_action {
  39. type = "redirect"
  40. redirect {
  41. port = "443"
  42. protocol = "HTTPS"
  43. status_code = "HTTP_301"
  44. }
  45. }
  46. }
  47. #########################
  48. # Targets
  49. resource "aws_lb_target_group" "alsi-alb-hec-target-8088" {
  50. count = local.alsi_hec_alb ? 1 : 0
  51. name = "${var.prefix}-alsi-hec-8088"
  52. port = 8088
  53. protocol = "HTTPS"
  54. target_type = "instance"
  55. vpc_id = var.vpc_id
  56. tags = merge(local.standard_tags, var.tags)
  57. health_check {
  58. enabled = true
  59. path = "/api/v1/health"
  60. port = 9000
  61. protocol = "HTTPS"
  62. }
  63. # sure would be nice to check the actual port
  64. #health_check {
  65. # enabled = true
  66. # path = "/"
  67. # port = 9000
  68. # protocol = "HTTPS"
  69. #}
  70. }
  71. resource "aws_lb_target_group_attachment" "alsi-alb-hec-target-8088-instance" {
  72. count = local.alsi_workers * (local.alsi_hec_alb ? 1 : 0)
  73. target_group_arn = aws_lb_target_group.alsi-alb-hec-target-8088[0].arn
  74. target_id = aws_instance.worker[count.index].id
  75. port = 8088
  76. }
  77. #########################
  78. # Security Group for ALB
  79. resource "aws_security_group" "alsi-alb-hec-sg" {
  80. name_prefix = "${var.prefix}-alsi-alb-hec-sg"
  81. lifecycle { create_before_destroy = true } # handle updates gracefully
  82. description = "Security Group for the Cribl ALB for hec"
  83. vpc_id = var.vpc_id
  84. tags = merge(local.standard_tags, var.tags)
  85. }
  86. resource "aws_security_group_rule" "alsi-alb-hec-https-in" {
  87. type = "ingress"
  88. from_port = 443
  89. to_port = 443
  90. protocol = "tcp"
  91. cidr_blocks = toset(concat(local.cidr_map["vpc-access"], local.trusted_ips, local.splunk_data_sources))
  92. security_group_id = aws_security_group.alsi-alb-hec-sg.id
  93. }
  94. resource "aws_security_group_rule" "alsi-elastic-http-in" {
  95. # Port 80 is open as a redirect to 443
  96. type = "ingress"
  97. from_port = 80
  98. to_port = 80
  99. protocol = "tcp"
  100. cidr_blocks = toset(concat(local.cidr_map["vpc-access"], local.trusted_ips, local.splunk_data_sources))
  101. security_group_id = aws_security_group.alsi-alb-hec-sg.id
  102. }
  103. resource "aws_security_group_rule" "alsi-alb-hec-8088-out" {
  104. type = "egress"
  105. from_port = 8088
  106. to_port = 8088
  107. protocol = "tcp"
  108. source_security_group_id = aws_security_group.alsi_worker_security_group.id
  109. security_group_id = aws_security_group.alsi-alb-hec-sg.id
  110. }
  111. #########################
  112. # DNS Entry
  113. resource "aws_route53_record" "alsi-alb-hec" {
  114. count = local.alsi_hec_alb ? 1 : 0
  115. zone_id = var.dns_info["public"]["zone_id"]
  116. name = "${var.prefix}-alsi-hec"
  117. type = "CNAME"
  118. records = [aws_lb.alsi-alb-hec[count.index].dns_name]
  119. ttl = "60"
  120. provider = aws.mdr-common-services-commercial
  121. }