elb-without-ack.tf 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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(var.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(var.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
  100. }
  101. resource "aws_lb_listener" "hec_443" {
  102. count = local.is_moose ? 1 : 0
  103. load_balancer_arn = aws_lb.hec.arn
  104. port = 443
  105. protocol = "HTTPS"
  106. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  107. certificate_arn = aws_acm_certificate.hec_cert.arn
  108. default_action {
  109. type = "forward"
  110. target_group_arn = aws_lb_target_group.hec_8088.arn
  111. }
  112. }
  113. resource "aws_lb_listener" "hec_8088" {
  114. load_balancer_arn = aws_lb.hec.arn
  115. port = 8088
  116. protocol = "HTTPS"
  117. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  118. certificate_arn = aws_acm_certificate.hec_cert.arn
  119. default_action {
  120. type = "forward"
  121. target_group_arn = aws_lb_target_group.hec_8088.arn
  122. }
  123. }
  124. resource "aws_lb_target_group" "hec_8088" {
  125. name = "${var.prefix}-legacy-hec-targets"
  126. port = 8088
  127. protocol = "HTTPS"
  128. target_type = "instance"
  129. vpc_id = var.vpc_id
  130. health_check {
  131. path = "/services/collector/health/1.0"
  132. protocol = "HTTPS"
  133. }
  134. }
  135. # Attach the instnaces to the ELB
  136. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  137. for_each = toset( var.elb_attachments )
  138. alb_target_group_arn = aws_lb_target_group.hec_8088.arn
  139. autoscaling_group_name = each.key
  140. }