nlb.tf 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. idle_timeout = 300
  22. access_logs {
  23. bucket = "xdr-elb-${var.environment}"
  24. enabled = true
  25. }
  26. tags = merge(local.standard_tags, var.tags)
  27. }
  28. resource "aws_lb_listener" "nlb_443" {
  29. load_balancer_arn = aws_lb.external.arn
  30. port = "443"
  31. protocol = "TCP"
  32. default_action {
  33. type = "forward"
  34. target_group_arn = aws_lb_target_group.external.arn
  35. }
  36. }
  37. resource "aws_lb_target_group" "external" {
  38. name = "rhsso-external-nlb"
  39. port = 8443
  40. protocol = "TCP"
  41. vpc_id = var.vpc_id
  42. target_type = "instance"
  43. health_check {
  44. enabled = true
  45. #healthy_threshold = 3
  46. #unhealthy_threshold = 2
  47. timeout = 10
  48. interval = 10
  49. #matcher = "200,302"
  50. path = "/"
  51. protocol = "HTTPS"
  52. }
  53. stickiness {
  54. enabled = true
  55. type = "source_ip" # only option for NLBs
  56. }
  57. }
  58. # Create a new load balancer attachment
  59. resource "aws_lb_target_group_attachment" "external_attachment" {
  60. count = local.instance_count
  61. target_group_arn = aws_lb_target_group.external.arn
  62. target_id = aws_instance.instance[count.index].id
  63. }