alb.tf 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #----------------------------------------------------------------------------
  2. # INTERNAL LB
  3. #----------------------------------------------------------------------------
  4. resource "aws_alb" "vmray_internal" {
  5. name = "vmray-alb-internal-${var.environment}"
  6. security_groups = [aws_security_group.vmray_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 = "vmray-alb-internal-${var.environment}" })
  17. }
  18. # Create a new target group
  19. resource "aws_alb_target_group" "vmray_internal" {
  20. name = "vmray-alb-targets"
  21. port = 443
  22. protocol = "HTTPS"
  23. vpc_id = var.vpc_id
  24. health_check {
  25. protocol = "HTTPS"
  26. port = "443"
  27. path = "/"
  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)
  39. }
  40. resource "aws_lb_target_group_attachment" "vmray_internal" {
  41. target_group_arn = aws_alb_target_group.vmray_internal.arn
  42. target_id = aws_instance.vmray-server-instance.id
  43. port = 443
  44. }
  45. # Create a new alb listener
  46. resource "aws_alb_listener" "vmray_https_internal" {
  47. load_balancer_arn = aws_alb.vmray_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_alb_target_group.vmray_internal.arn
  54. type = "forward"
  55. }
  56. }
  57. resource "aws_lb_listener" "vmray_listener_http" {
  58. load_balancer_arn = aws_alb.vmray_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 "private_dns_record" {
  73. source = "../../submodules/dns/private_CNAME_record"
  74. name = "vmray"
  75. target_dns_names = [aws_alb.vmray_internal.dns_name]
  76. dns_info = var.dns_info
  77. providers = {
  78. aws.c2 = aws.c2
  79. }
  80. }
  81. #----------------------------------------------------------------------------
  82. # VMRAY ALB Security Group
  83. #----------------------------------------------------------------------------
  84. resource "aws_security_group" "vmray_alb_internal" {
  85. vpc_id = var.vpc_id
  86. name = "vmray-alb-sg-internal"
  87. description = "ALB for Phantom"
  88. tags = merge(local.standard_tags, var.tags)
  89. }
  90. #----------------------------------------------------------------------------
  91. # INGRESS
  92. #----------------------------------------------------------------------------
  93. resource "aws_security_group_rule" "http_from_local" {
  94. type = "ingress"
  95. description = "HTTP - Inbound from Internet"
  96. from_port = "80"
  97. to_port = "80"
  98. protocol = "tcp"
  99. cidr_blocks = concat(local.cidr_map["vpc-access"], local.cidr_map["vpc-private-services"])
  100. security_group_id = aws_security_group.vmray_alb_internal.id
  101. }
  102. resource "aws_security_group_rule" "https_from_local" {
  103. type = "ingress"
  104. description = "HTTPS - Inbound from Internet"
  105. from_port = "443"
  106. to_port = "443"
  107. protocol = "tcp"
  108. cidr_blocks = concat(local.cidr_map["vpc-access"], local.cidr_map["vpc-private-services"])
  109. security_group_id = aws_security_group.vmray_alb_internal.id
  110. }
  111. #----------------------------------------------------------------------------
  112. # EGRESS
  113. #----------------------------------------------------------------------------
  114. resource "aws_security_group_rule" "vmray_alb_to_server" {
  115. type = "egress"
  116. description = "HTTPS to the Server"
  117. from_port = "443"
  118. to_port = "443"
  119. protocol = "tcp"
  120. source_security_group_id = aws_security_group.vmray_server_sg.id
  121. security_group_id = aws_security_group.vmray_alb_internal.id
  122. }