lb_internal.tf 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #----------------------------------------------------------------------------
  2. # INTERNAL LB
  3. #----------------------------------------------------------------------------
  4. resource "aws_lb" "internal" {
  5. name_prefix = substr(var.instance_name, 0, 6)
  6. security_groups = [aws_security_group.alb_internal.id]
  7. internal = true
  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. idle_timeout = 1200
  16. tags = merge(local.standard_tags, var.tags, { Name = "reposerver-internal-${var.environment}" })
  17. }
  18. # Create a new target group
  19. resource "aws_lb_target_group" "internal" {
  20. name_prefix = substr(var.instance_name, 1, 6)
  21. port = 80
  22. protocol = "HTTP"
  23. vpc_id = var.vpc_id
  24. health_check {
  25. protocol = "HTTP"
  26. port = "80"
  27. path = "/epel/7/repodata/repomd.xml"
  28. matcher = "200,302"
  29. timeout = "4"
  30. interval = "5"
  31. unhealthy_threshold = 2
  32. healthy_threshold = 2
  33. }
  34. #stickiness {
  35. # type = "lb_cookie"
  36. # enabled = false
  37. #}
  38. tags = merge(local.standard_tags, var.tags, { Name = "reposerver-internal-${var.environment}" })
  39. }
  40. resource "aws_lb_target_group_attachment" "internal" {
  41. target_group_arn = aws_lb_target_group.internal.arn
  42. target_id = aws_instance.instance.id
  43. port = 80
  44. }
  45. # Create a new alb listener
  46. resource "aws_lb_listener" "https_internal" {
  47. load_balancer_arn = aws_lb.internal.arn
  48. port = "443"
  49. protocol = "HTTPS"
  50. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  51. certificate_arn = aws_acm_certificate.cert_private.arn
  52. default_action {
  53. target_group_arn = aws_lb_target_group.internal.arn
  54. type = "forward"
  55. }
  56. }
  57. resource "aws_lb_listener" "listener_http" {
  58. load_balancer_arn = aws_lb.internal.arn
  59. port = "80"
  60. protocol = "HTTP"
  61. default_action {
  62. type = "redirect"
  63. redirect {
  64. port = "443"
  65. protocol = "HTTPS"
  66. status_code = "HTTP_301"
  67. }
  68. }
  69. }
  70. # #########################
  71. # # DNS Entry
  72. module "internal_lb_private_dns_record" {
  73. source = "../../submodules/dns/private_CNAME_record"
  74. name = "reposerver"
  75. target_dns_names = [aws_lb.internal.dns_name]
  76. dns_info = var.dns_info
  77. providers = {
  78. aws.c2 = aws.c2
  79. }
  80. }
  81. #----------------------------------------------------------------------------
  82. # ALB Security Group
  83. #----------------------------------------------------------------------------
  84. resource "aws_security_group" "alb_internal" {
  85. vpc_id = var.vpc_id
  86. name_prefix = "repo_alb"
  87. description = "ALB for Repo Server Internal ALB"
  88. tags = merge(local.standard_tags, var.tags)
  89. }
  90. #----------------------------------------------------------------------------
  91. # INGRESS
  92. #----------------------------------------------------------------------------
  93. resource "aws_security_group_rule" "http_from_local" {
  94. description = "HTTP inbound from Private Servers"
  95. type = "ingress"
  96. from_port = "80"
  97. to_port = "80"
  98. protocol = "tcp"
  99. cidr_blocks = ["10.0.0.0/8"]
  100. security_group_id = aws_security_group.alb_internal.id
  101. }
  102. resource "aws_security_group_rule" "https_from_local" {
  103. description = "HTTPS inbound from private servers"
  104. type = "ingress"
  105. from_port = "443"
  106. to_port = "443"
  107. protocol = "tcp"
  108. cidr_blocks = ["10.0.0.0/8"]
  109. security_group_id = aws_security_group.alb_internal.id
  110. }
  111. #----------------------------------------------------------------------------
  112. # EGRESS
  113. #----------------------------------------------------------------------------
  114. resource "aws_security_group_rule" "alb_to_server" {
  115. description = "HTTP to the Server"
  116. type = "egress"
  117. from_port = "80"
  118. to_port = "80"
  119. protocol = "tcp"
  120. source_security_group_id = aws_security_group.repo_server_security_group.id
  121. security_group_id = aws_security_group.alb_internal.id
  122. }