nlb.tf 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # KeyCloak Needs an NLB:
  2. # * ALB/ELB can't terminate SSL, because RHSSO needs the certificate
  3. # * Because they don't terminate SSL, they can't provide X-forwarded-for, and rhsso needs the source IP
  4. # * Therefore, we use an NLB and preserve the source IP.
  5. module "public_dns_record" {
  6. source = "../../submodules/dns/public_ALIAS_record"
  7. name = "auth.${var.dns_info["public"]["zone"]}"
  8. target_dns_name = aws_lb.external.dns_name
  9. target_zone_id = aws_lb.external.zone_id
  10. dns_info = var.dns_info
  11. providers = {
  12. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  13. }
  14. }
  15. resource "aws_lb" "external" {
  16. name = "rhsso-external-nlb"
  17. load_balancer_type = "network"
  18. internal = false # tfsec:ignore:aws-elb-alb-not-public
  19. subnets = var.public_subnets
  20. enable_cross_zone_load_balancing = true
  21. access_logs {
  22. bucket = "xdr-elb-${var.environment}"
  23. enabled = true
  24. }
  25. enable_cross_zone_load_balancing = true
  26. idle_timeout = 300
  27. tags = merge(local.standard_tags, var.tags)
  28. }
  29. resource "aws_lb_listener" "nlb_443" {
  30. load_balancer_arn = aws_lb.external.arn
  31. port = "443"
  32. protocol = "TCP"
  33. default_action {
  34. type = "forward"
  35. target_group_arn = aws_lb_target_group.external.arn
  36. }
  37. }
  38. resource "aws_lb_target_group" "external" {
  39. name = "rhsso-external-nlb"
  40. port = 8443
  41. protocol = "TCP"
  42. vpc_id = var.vpc_id
  43. target_type = "instance"
  44. health_check {
  45. enabled = true
  46. #healthy_threshold = 3
  47. #unhealthy_threshold = 2
  48. timeout = 10
  49. interval = 10
  50. #matcher = "200,302"
  51. path = "/"
  52. protocol = "HTTPS"
  53. }
  54. stickiness {
  55. enabled = true
  56. type = "source_ip" # only option for NLBs
  57. }
  58. }
  59. # Create a new load balancer attachment
  60. resource "aws_lb_target_group_attachment" "external_attachment" {
  61. count = local.instance_count
  62. target_group_arn = aws_lb_target_group.external.arn
  63. target_id = aws_instance.instance[count.index].id
  64. }