elb-without-ack.tf 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. provider = aws.legacy
  21. }
  22. output hec-without-ack-fqdn {
  23. value = aws_route53_record.hec.fqdn
  24. }
  25. resource "aws_route53_record" "iratemoses" {
  26. count = local.is_moose ? 1 : 0
  27. name = "iratemoses"
  28. type = "CNAME"
  29. zone_id = var.dns_info["legacy_public"]["zone_id"]
  30. ttl = "600"
  31. records = [ aws_lb.hec.dns_name ]
  32. provider = aws.legacy
  33. }
  34. resource "aws_route53_record" "iratemoses_public_internal" {
  35. count = local.is_moose ? 1 : 0
  36. name = "iratemoses"
  37. type = "CNAME"
  38. zone_id = var.dns_info["legacy_public_internal"]["zone_id"]
  39. ttl = "600"
  40. records = [ aws_lb.hec.dns_name ]
  41. provider = aws.legacy
  42. }
  43. resource "aws_route53_record" "iratemoses_public" {
  44. count = local.is_moose ? 1 : 0
  45. name = "iratemoses"
  46. type = "CNAME"
  47. zone_id = var.dns_info["public"]["zone_id"]
  48. ttl = "600"
  49. records = [ aws_lb.hec.dns_name ]
  50. provider = aws.mdr-common-services-commercial
  51. }
  52. output hec-without-ack-iratemoses-fqdn {
  53. value = local.is_moose ? aws_route53_record.iratemoses[0].fqdn : "<not created for non-moose>"
  54. }
  55. output hec-without-ack-records {
  56. value = aws_lb.hec.dns_name
  57. }
  58. #########################
  59. # Certificate
  60. resource "aws_acm_certificate" "hec_cert" {
  61. domain_name = "${var.prefix}-hec.${var.dns_info["legacy_public"]["zone"]}"
  62. validation_method = "DNS"
  63. subject_alternative_names = local.is_moose ? [ "iratemoses.${var.dns_info["legacy_public"]["zone"]}" ] : [ ]
  64. tags = merge(var.standard_tags, var.tags)
  65. }
  66. resource "aws_acm_certificate_validation" "hec_cert_validation" {
  67. certificate_arn = aws_acm_certificate.hec_cert.arn
  68. validation_record_fqdns = [for record in aws_route53_record.hec_cert_validation: record.fqdn]
  69. }
  70. resource "aws_route53_record" "hec_cert_validation" {
  71. provider = aws.legacy
  72. for_each = {
  73. for dvo in aws_acm_certificate.hec_cert.domain_validation_options : dvo.domain_name => {
  74. name = dvo.resource_record_name
  75. record = dvo.resource_record_value
  76. type = dvo.resource_record_type
  77. }
  78. }
  79. allow_overwrite = true
  80. name = each.value.name
  81. records = [each.value.record]
  82. ttl = 60
  83. type = each.value.type
  84. zone_id = var.dns_info["legacy_public"]["zone_id"]
  85. }
  86. #########################
  87. # ELB
  88. resource "aws_lb" "hec" {
  89. tags = merge(var.standard_tags, var.tags)
  90. name = "${var.prefix}-legacy-hec"
  91. load_balancer_type = "application"
  92. security_groups = [ data.aws_security_group.hec_elb_security_group.id ]
  93. subnets = var.public_subnets
  94. internal = false
  95. }
  96. resource "aws_lb_listener" "hec_443" {
  97. count = local.is_moose ? 1 : 0
  98. load_balancer_arn = aws_lb.hec.arn
  99. port = 443
  100. protocol = "HTTPS"
  101. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  102. certificate_arn = aws_acm_certificate.hec_cert.arn
  103. default_action {
  104. type = "forward"
  105. target_group_arn = aws_lb_target_group.hec_8088.arn
  106. }
  107. }
  108. resource "aws_lb_listener" "hec_8088" {
  109. load_balancer_arn = aws_lb.hec.arn
  110. port = 8088
  111. protocol = "HTTPS"
  112. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  113. certificate_arn = aws_acm_certificate.hec_cert.arn
  114. default_action {
  115. type = "forward"
  116. target_group_arn = aws_lb_target_group.hec_8088.arn
  117. }
  118. }
  119. resource "aws_lb_target_group" "hec_8088" {
  120. name = "${var.prefix}-legacy-hec-targets"
  121. port = 8088
  122. protocol = "HTTPS"
  123. target_type = "instance"
  124. vpc_id = var.vpc_id
  125. health_check {
  126. path = "/services/collector/health/1.0"
  127. protocol = "HTTPS"
  128. }
  129. }
  130. # Attach the instnaces to the ELB
  131. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  132. for_each = toset( var.elb_attachments )
  133. alb_target_group_arn = aws_lb_target_group.hec_8088.arn
  134. autoscaling_group_name = each.key
  135. }