elb.tf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #----------------------------------------------------------------------------
  2. # EXTERNAL LB
  3. #----------------------------------------------------------------------------
  4. resource "aws_lb" "external" {
  5. name_prefix = substr("${var.name}-ext-lb", 0, 6)
  6. security_groups = [aws_security_group.lb_server_external.id]
  7. internal = false #tfsec:ignore:aws-elb-alb-not-public
  8. subnets = var.public_subnets
  9. load_balancer_type = "application"
  10. drop_invalid_header_fields = true
  11. access_logs {
  12. bucket = "xdr-elb-${var.environment}"
  13. enabled = true
  14. }
  15. tags = merge(var.tags, { Name = "${var.name}-lb-external-${var.environment}" })
  16. }
  17. # Create a new target group
  18. resource "aws_lb_target_group" "external" {
  19. name_prefix = substr("${var.name}-ext-lb", 0, 6)
  20. port = var.target_port
  21. protocol = var.target_protocol
  22. #deregistration_delay = "${local.lb_deregistration_delay}"
  23. vpc_id = var.vpc_id
  24. health_check {
  25. protocol = local.healthcheck_protocol
  26. port = local.healthcheck_port
  27. path = var.healthcheck_path
  28. matcher = var.healthcheck_matcher
  29. timeout = "4"
  30. interval = "5"
  31. }
  32. stickiness {
  33. type = "lb_cookie"
  34. enabled = var.stickiness
  35. }
  36. tags = merge(var.tags, { Name = "${var.name}-lb-external-${var.environment}" })
  37. }
  38. resource "aws_lb_target_group_attachment" "external" {
  39. for_each = var.target_ids
  40. target_group_arn = aws_lb_target_group.external.arn
  41. target_id = each.value
  42. port = var.target_port
  43. }
  44. # Create a new alb listener
  45. resource "aws_lb_listener" "https_external" {
  46. load_balancer_arn = aws_lb.external.arn
  47. port = var.listener_port
  48. protocol = "HTTPS"
  49. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  50. certificate_arn = aws_acm_certificate.cert_public.arn
  51. default_action {
  52. target_group_arn = aws_lb_target_group.external.arn
  53. type = "forward"
  54. }
  55. }