elb.tf 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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
  8. subnets = var.public_subnets
  9. load_balancer_type = "application"
  10. access_logs {
  11. bucket = "xdr-elb-${ var.environment }"
  12. enabled = true
  13. }
  14. tags = merge(var.tags, { Name = "${var.name}-lb-external-${var.environment}" })
  15. }
  16. # Create a new target group
  17. resource "aws_lb_target_group" "external" {
  18. name_prefix = substr("${var.name}-ext-lb", 0, 6)
  19. port = var.target_port
  20. protocol = var.target_protocol
  21. #deregistration_delay = "${local.lb_deregistration_delay}"
  22. vpc_id = var.vpc_id
  23. health_check {
  24. protocol = local.healthcheck_protocol
  25. port = local.healthcheck_port
  26. path = var.healthcheck_path
  27. matcher = var.healthcheck_matcher
  28. timeout = "4"
  29. interval = "5"
  30. }
  31. stickiness {
  32. type = "lb_cookie"
  33. enabled = var.stickiness
  34. }
  35. tags = merge(var.tags, { Name = "${var.name}-lb-external-${var.environment}" })
  36. }
  37. resource "aws_lb_target_group_attachment" "external" {
  38. for_each = var.target_ids
  39. target_group_arn = aws_lb_target_group.external.arn
  40. target_id = each.value
  41. port = var.target_port
  42. }
  43. # Create a new alb listener
  44. resource "aws_lb_listener" "https_external" {
  45. load_balancer_arn = aws_lb.external.arn
  46. port = var.listener_port
  47. protocol = "HTTPS"
  48. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2019-08" # PFS, TLS1.2, most "restrictive" policy (took awhile to find that)
  49. certificate_arn = aws_acm_certificate.cert_public.arn
  50. default_action {
  51. target_group_arn = aws_lb_target_group.external.arn
  52. type = "forward"
  53. }
  54. }