elb.tf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #----------------------------------------------------------------------------
  2. # INTERNAL LB
  3. #----------------------------------------------------------------------------
  4. resource "aws_alb" "vault" {
  5. name = "vault-alb-${var.environment}"
  6. security_groups = [aws_security_group.vault_ALB_server.id]
  7. internal = true
  8. subnets = var.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(local.standard_tags, var.tags, { Name = "vault-alb-${var.environment}" })
  16. }
  17. # Create a new target group
  18. resource "aws_alb_target_group" "vault" {
  19. name = "vault-alb-targets-https-${var.environment}"
  20. port = 443
  21. protocol = "HTTPS"
  22. #deregistration_delay = "${local.lb_deregistration_delay}"
  23. vpc_id = var.vpc_id
  24. health_check {
  25. protocol = "HTTPS"
  26. path = "/v1/sys/health"
  27. matcher = "200"
  28. timeout = "4"
  29. interval = "5"
  30. }
  31. stickiness {
  32. type = "lb_cookie"
  33. enabled = false
  34. }
  35. tags = merge(local.standard_tags, var.tags)
  36. }
  37. resource "aws_lb_target_group_attachment" "vault" {
  38. for_each = toset(var.instance_count)
  39. target_group_arn = aws_alb_target_group.vault.arn
  40. target_id = aws_instance.instance[each.key].id
  41. port = 443
  42. }
  43. # Create a new alb listener
  44. resource "aws_alb_listener" "vault_https" {
  45. load_balancer_arn = aws_alb.vault.arn
  46. port = "443"
  47. protocol = "HTTPS"
  48. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  49. certificate_arn = aws_acm_certificate.cert.arn
  50. default_action {
  51. target_group_arn = aws_alb_target_group.vault.arn
  52. type = "forward"
  53. }
  54. }
  55. # #########################
  56. # # DNS Entry
  57. # module "public_dns_record" {
  58. # source = "../../submodules/dns/public_ALIAS_record"
  59. # name = var.instance_name
  60. # target_dns_name = aws_lb.openvpn-nlb.dns_name
  61. # target_zone_id = aws_lb.openvpn-nlb.zone_id
  62. # dns_info = var.dns_info
  63. # providers = {
  64. # aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  65. # }
  66. # }
  67. #----------
  68. # DNS Entry
  69. #----------
  70. #DNS Alias for the LB ( the CNAME was required. an Alias did NOT work due to aws/bug. )
  71. resource "aws_route53_record" "vault_internal" {
  72. zone_id = var.dns_info["private"]["zone_id"]
  73. name = var.instance_name
  74. type = "CNAME"
  75. records = [aws_alb.vault.dns_name]
  76. ttl = "60"
  77. provider = aws.c2
  78. }
  79. #----------------------------------------------------------------------------
  80. # Vault ALB Security Group
  81. #----------------------------------------------------------------------------
  82. resource "aws_security_group" "vault_ALB_server" {
  83. vpc_id = var.vpc_id
  84. name = "vault-alb-sg"
  85. description = "ALB for Vault"
  86. tags = merge(local.standard_tags, var.tags)
  87. }
  88. #----------------------------------------------------------------------------
  89. # INGRESS
  90. #----------------------------------------------------------------------------
  91. resource "aws_security_group_rule" "vault_server_from_vpc" {
  92. type = "ingress"
  93. from_port = 443
  94. to_port = 443
  95. protocol = "tcp"
  96. cidr_blocks = ["10.0.0.0/8"]
  97. description = "Allows the server to receive traffic from everywhere"
  98. security_group_id = aws_security_group.vault_ALB_server.id
  99. }
  100. #----------------------------------------------------------------------------
  101. # EGRESS
  102. #----------------------------------------------------------------------------
  103. resource "aws_security_group_rule" "alb_to_vault_server" {
  104. type = "egress"
  105. from_port = 443
  106. to_port = 443
  107. protocol = "tcp"
  108. source_security_group_id = aws_security_group.instance_security_group.id
  109. description = "Allows the ALB to talk to the vault servers"
  110. security_group_id = aws_security_group.vault_ALB_server.id
  111. }