elb.tf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #----------------------------------------------------------------------------
  2. # EXTERNAL LB
  3. #----------------------------------------------------------------------------
  4. resource "aws_alb" "jira_server_external" {
  5. name = "jira-server-alb-external-${var.environment}"
  6. security_groups = [ aws_security_group.jira_server_alb_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. idle_timeout = 1200
  15. tags = merge(var.standard_tags, var.tags, { Name = "jira-server-alb-external-${var.environment}" })
  16. }
  17. # Create a new target group
  18. resource "aws_alb_target_group" "jira_server_external" {
  19. name = "jira-server-alb-targets"
  20. port = 8080
  21. protocol = "HTTP"
  22. vpc_id = var.vpc_id
  23. health_check {
  24. protocol = "HTTP"
  25. port = "8080"
  26. path = "/"
  27. matcher = "200,302"
  28. timeout = "4"
  29. interval = "5"
  30. unhealthy_threshold = 2
  31. healthy_threshold = 2
  32. }
  33. #stickiness {
  34. # type = "lb_cookie"
  35. # enabled = false
  36. #}
  37. tags = merge(var.standard_tags, var.tags)
  38. }
  39. resource "aws_lb_target_group_attachment" "jira_server_external" {
  40. target_group_arn = aws_alb_target_group.jira_server_external.arn
  41. target_id = aws_instance.jira-server-instance.id
  42. port = 8080
  43. }
  44. # Create a new alb listener
  45. resource "aws_alb_listener" "jira_server_https_external" {
  46. load_balancer_arn = aws_alb.jira_server_external.arn
  47. port = "443"
  48. protocol = "HTTPS"
  49. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2019-08" # PFS, TLS1.2, most "restrictive" policy (took awhile to find that)
  50. certificate_arn = aws_acm_certificate.cert_public.arn
  51. default_action {
  52. target_group_arn = aws_alb_target_group.jira_server_external.arn
  53. type = "forward"
  54. }
  55. }
  56. resource "aws_lb_listener" "jira_server_listener_http" {
  57. load_balancer_arn = aws_alb.jira_server_external.arn
  58. port = "80"
  59. protocol = "HTTP"
  60. default_action {
  61. type = "redirect"
  62. redirect {
  63. port = "443"
  64. protocol = "HTTPS"
  65. status_code = "HTTP_301"
  66. }
  67. }
  68. }
  69. # #########################
  70. # # DNS Entry
  71. module "public_dns_record" {
  72. source = "../../../submodules/dns/public_ALIAS_record"
  73. name = "jira"
  74. target_dns_name = aws_alb.jira_server_external.dns_name
  75. target_zone_id = aws_alb.jira_server_external.zone_id
  76. dns_info = var.dns_info
  77. providers = {
  78. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  79. }
  80. }
  81. #----------------------------------------------------------------------------
  82. # ALB Security Group
  83. #----------------------------------------------------------------------------
  84. resource "aws_security_group" "jira_server_alb_server_external" {
  85. vpc_id = var.vpc_id
  86. name = "jira-server-alb-sg-external"
  87. description = "ALB for JIRA"
  88. tags = merge(var.standard_tags, var.tags)
  89. }
  90. #----------------------------------------------------------------------------
  91. # INGRESS
  92. #----------------------------------------------------------------------------
  93. resource "aws_security_group_rule" "http_from_internet" {
  94. description = "HTTP inbound from Internet"
  95. type = "ingress"
  96. from_port = "80"
  97. to_port = "80"
  98. protocol = "tcp"
  99. cidr_blocks = [ "0.0.0.0/0" ]
  100. security_group_id = aws_security_group.jira_server_alb_server_external.id
  101. }
  102. resource "aws_security_group_rule" "https_from_internet" {
  103. description = "HTTPS inbound from Internet"
  104. type = "ingress"
  105. from_port = "443"
  106. to_port = "443"
  107. protocol = "tcp"
  108. cidr_blocks = [ "0.0.0.0/0" ]
  109. security_group_id = aws_security_group.jira_server_alb_server_external.id
  110. }
  111. #----------------------------------------------------------------------------
  112. # EGRESS
  113. #----------------------------------------------------------------------------
  114. resource "aws_security_group_rule" "jira_alb_to_server" {
  115. description = "Jira to the Server"
  116. type = "egress"
  117. from_port = "8080"
  118. to_port = "8080"
  119. protocol = "tcp"
  120. source_security_group_id = aws_security_group.jira_server.id
  121. security_group_id = aws_security_group.jira_server_alb_server_external.id
  122. }