elb-master.tf 3.6 KB

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