elb.tf 3.3 KB

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