elb-without-ack.tf 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #------------------------------------------------------------------------------
  2. # An external ALB for the indexers for HEC
  3. #------------------------------------------------------------------------------
  4. #########################
  5. # DNS Entry
  6. resource "aws_route53_record" "hec" {
  7. name = "${var.prefix}-hec"
  8. type = "CNAME"
  9. zone_id = var.dns_info["legacy_public"]["zone_id"]
  10. ttl = "600"
  11. records = [aws_lb.hec.dns_name]
  12. provider = aws.legacy
  13. }
  14. #resource "aws_route53_record" "hec_public_internal" {
  15. # name = "${var.prefix}-hec"
  16. # type = "CNAME"
  17. # zone_id = var.dns_info["legacy_public_internal"]["zone_id"]
  18. # ttl = "600"
  19. # records = [ aws_lb.hec.dns_name ]
  20. #
  21. # provider = aws.legacy
  22. #}
  23. output "hec-without-ack-fqdn" {
  24. value = aws_route53_record.hec.fqdn
  25. }
  26. resource "aws_route53_record" "iratemoses" {
  27. count = local.is_moose ? 1 : 0
  28. name = "iratemoses"
  29. type = "CNAME"
  30. zone_id = var.dns_info["legacy_public"]["zone_id"]
  31. ttl = "600"
  32. records = [aws_lb.hec.dns_name]
  33. provider = aws.legacy
  34. }
  35. #resource "aws_route53_record" "iratemoses_public_internal" {
  36. # count = local.is_moose ? 1 : 0
  37. # name = "iratemoses"
  38. # type = "CNAME"
  39. # zone_id = var.dns_info["legacy_public_internal"]["zone_id"]
  40. # ttl = "600"
  41. # records = [ aws_lb.hec.dns_name ]
  42. #
  43. # provider = aws.legacy
  44. #}
  45. resource "aws_route53_record" "iratemoses_public" {
  46. count = local.is_moose ? 1 : 0
  47. name = "iratemoses"
  48. type = "CNAME"
  49. zone_id = var.dns_info["public"]["zone_id"]
  50. ttl = "600"
  51. records = [aws_lb.hec.dns_name]
  52. provider = aws.mdr-common-services-commercial
  53. }
  54. output "hec-without-ack-iratemoses-fqdn" {
  55. value = local.is_moose ? aws_route53_record.iratemoses[0].fqdn : "<not created for non-moose>"
  56. }
  57. output "hec-without-ack-records" {
  58. value = aws_lb.hec.dns_name
  59. }
  60. #########################
  61. # Certificate
  62. resource "aws_acm_certificate" "hec_cert" {
  63. domain_name = "${var.prefix}-hec.${var.dns_info["legacy_public"]["zone"]}"
  64. validation_method = "DNS"
  65. lifecycle {
  66. create_before_destroy = true
  67. }
  68. subject_alternative_names = local.is_moose ? ["iratemoses.${var.dns_info["legacy_public"]["zone"]}"] : []
  69. tags = merge(local.standard_tags, var.tags)
  70. }
  71. resource "aws_acm_certificate_validation" "hec_cert_validation" {
  72. certificate_arn = aws_acm_certificate.hec_cert.arn
  73. validation_record_fqdns = [for record in aws_route53_record.hec_cert_validation : record.fqdn]
  74. }
  75. resource "aws_route53_record" "hec_cert_validation" {
  76. provider = aws.legacy
  77. for_each = {
  78. for dvo in aws_acm_certificate.hec_cert.domain_validation_options : dvo.domain_name => {
  79. name = dvo.resource_record_name
  80. record = dvo.resource_record_value
  81. type = dvo.resource_record_type
  82. }
  83. }
  84. allow_overwrite = true
  85. name = each.value.name
  86. records = [each.value.record]
  87. ttl = 60
  88. type = each.value.type
  89. zone_id = var.dns_info["legacy_public"]["zone_id"]
  90. }
  91. #########################
  92. # ELB
  93. resource "aws_lb" "hec" {
  94. tags = merge(local.standard_tags, var.tags)
  95. name = "${var.prefix}-legacy-hec"
  96. load_balancer_type = "application"
  97. security_groups = [data.aws_security_group.hec_elb_security_group.id]
  98. subnets = var.public_subnets
  99. internal = false # tfsec:ignore:aws-elb-alb-not-public The ELB requires Internet exposure
  100. drop_invalid_header_fields = true
  101. }
  102. resource "aws_lb_listener" "hec_443" {
  103. count = local.is_moose ? 1 : 0
  104. load_balancer_arn = aws_lb.hec.arn
  105. port = 443
  106. protocol = "HTTPS"
  107. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  108. certificate_arn = aws_acm_certificate.hec_cert.arn
  109. default_action {
  110. type = "forward"
  111. target_group_arn = aws_lb_target_group.hec_8088.arn
  112. }
  113. }
  114. resource "aws_lb_listener" "hec_8088" {
  115. load_balancer_arn = aws_lb.hec.arn
  116. port = 8088
  117. protocol = "HTTPS"
  118. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  119. certificate_arn = aws_acm_certificate.hec_cert.arn
  120. default_action {
  121. type = "forward"
  122. target_group_arn = aws_lb_target_group.hec_8088.arn
  123. }
  124. }
  125. resource "aws_lb_target_group" "hec_8088" {
  126. name = "${var.prefix}-legacy-hec-targets"
  127. port = 8088
  128. protocol = "HTTPS"
  129. target_type = "instance"
  130. vpc_id = var.vpc_id
  131. health_check {
  132. path = "/services/collector/health/1.0"
  133. protocol = "HTTPS"
  134. }
  135. }
  136. # Attach the instnaces to the ELB
  137. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  138. for_each = toset(var.elb_attachments)
  139. lb_target_group_arn = aws_lb_target_group.hec_8088.arn
  140. autoscaling_group_name = each.key
  141. }