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. #
  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. subject_alternative_names = local.is_moose ? [ "iratemoses.${var.dns_info["legacy_public"]["zone"]}" ] : [ ]
  66. tags = merge(var.standard_tags, var.tags)
  67. }
  68. resource "aws_acm_certificate_validation" "hec_cert_validation" {
  69. certificate_arn = aws_acm_certificate.hec_cert.arn
  70. validation_record_fqdns = [for record in aws_route53_record.hec_cert_validation: record.fqdn]
  71. }
  72. resource "aws_route53_record" "hec_cert_validation" {
  73. provider = aws.legacy
  74. for_each = {
  75. for dvo in aws_acm_certificate.hec_cert.domain_validation_options : dvo.domain_name => {
  76. name = dvo.resource_record_name
  77. record = dvo.resource_record_value
  78. type = dvo.resource_record_type
  79. }
  80. }
  81. allow_overwrite = true
  82. name = each.value.name
  83. records = [each.value.record]
  84. ttl = 60
  85. type = each.value.type
  86. zone_id = var.dns_info["legacy_public"]["zone_id"]
  87. }
  88. #########################
  89. # ELB
  90. resource "aws_lb" "hec" {
  91. tags = merge(var.standard_tags, var.tags)
  92. name = "${var.prefix}-legacy-hec"
  93. load_balancer_type = "application"
  94. security_groups = [ data.aws_security_group.hec_elb_security_group.id ]
  95. subnets = var.public_subnets
  96. internal = false
  97. }
  98. resource "aws_lb_listener" "hec_443" {
  99. count = local.is_moose ? 1 : 0
  100. load_balancer_arn = aws_lb.hec.arn
  101. port = 443
  102. protocol = "HTTPS"
  103. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  104. certificate_arn = aws_acm_certificate.hec_cert.arn
  105. default_action {
  106. type = "forward"
  107. target_group_arn = aws_lb_target_group.hec_8088.arn
  108. }
  109. }
  110. resource "aws_lb_listener" "hec_8088" {
  111. load_balancer_arn = aws_lb.hec.arn
  112. port = 8088
  113. protocol = "HTTPS"
  114. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  115. certificate_arn = aws_acm_certificate.hec_cert.arn
  116. default_action {
  117. type = "forward"
  118. target_group_arn = aws_lb_target_group.hec_8088.arn
  119. }
  120. }
  121. resource "aws_lb_target_group" "hec_8088" {
  122. name = "${var.prefix}-legacy-hec-targets"
  123. port = 8088
  124. protocol = "HTTPS"
  125. target_type = "instance"
  126. vpc_id = var.vpc_id
  127. health_check {
  128. path = "/services/collector/health/1.0"
  129. protocol = "HTTPS"
  130. }
  131. }
  132. # Attach the instnaces to the ELB
  133. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  134. for_each = toset( var.elb_attachments )
  135. alb_target_group_arn = aws_lb_target_group.hec_8088.arn
  136. autoscaling_group_name = each.key
  137. }