elb-without-ack.tf 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #------------------------------------------------------------------------------
  2. # An external ALB for the indexers for HEC
  3. #------------------------------------------------------------------------------
  4. #########################
  5. # DNS Entry
  6. module "public_dns_record_hec" {
  7. source = "../../../submodules/dns/public_ALIAS_record"
  8. name = "${var.prefix}-hec"
  9. target_dns_name = aws_lb.hec.dns_name
  10. target_zone_id = aws_lb.hec.zone_id
  11. dns_info = var.dns_info
  12. providers = {
  13. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  14. }
  15. }
  16. #########################
  17. # Certificate
  18. resource "aws_acm_certificate" "hec_cert" {
  19. domain_name = "${var.prefix}-hec.${var.dns_info["public"]["zone"]}"
  20. validation_method = "DNS"
  21. lifecycle {
  22. create_before_destroy = true
  23. }
  24. tags = merge(var.standard_tags, var.tags)
  25. }
  26. resource "aws_acm_certificate_validation" "hec_cert_validation" {
  27. certificate_arn = aws_acm_certificate.hec_cert.arn
  28. validation_record_fqdns = [for record in aws_route53_record.hec_cert_validation: record.fqdn]
  29. }
  30. resource "aws_route53_record" "hec_cert_validation" {
  31. provider = aws.mdr-common-services-commercial
  32. for_each = {
  33. for dvo in aws_acm_certificate.hec_cert.domain_validation_options : dvo.domain_name => {
  34. name = dvo.resource_record_name
  35. record = dvo.resource_record_value
  36. type = dvo.resource_record_type
  37. }
  38. }
  39. allow_overwrite = true
  40. name = each.value.name
  41. records = [each.value.record]
  42. ttl = 60
  43. type = each.value.type
  44. zone_id = var.dns_info["public"]["zone_id"]
  45. }
  46. #########################
  47. # ELB
  48. resource "aws_lb" "hec" {
  49. tags = merge(var.standard_tags, var.tags)
  50. name = "${var.prefix}-hec"
  51. load_balancer_type = "application"
  52. security_groups = [ aws_security_group.hec_elb_security_group.id ]
  53. subnets = var.public_subnets
  54. internal = false
  55. }
  56. resource "aws_lb_listener" "hec_443" {
  57. count = anytrue([ local.is_moose, var.hec_listen_443 ]) ? 1 : 0
  58. load_balancer_arn = aws_lb.hec.arn
  59. port = 443
  60. protocol = "HTTPS"
  61. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  62. certificate_arn = aws_acm_certificate.hec_cert.arn
  63. default_action {
  64. type = "forward"
  65. target_group_arn = aws_lb_target_group.hec_8088.arn
  66. }
  67. }
  68. resource "aws_lb_listener" "hec_8088" {
  69. load_balancer_arn = aws_lb.hec.arn
  70. port = 8088
  71. protocol = "HTTPS"
  72. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  73. certificate_arn = aws_acm_certificate.hec_cert.arn
  74. default_action {
  75. type = "forward"
  76. target_group_arn = aws_lb_target_group.hec_8088.arn
  77. }
  78. }
  79. resource "aws_lb_target_group" "hec_8088" {
  80. name = "${var.prefix}-hec-targets"
  81. port = 8088
  82. protocol = "HTTPS"
  83. target_type = "instance"
  84. vpc_id = var.vpc_id
  85. health_check {
  86. path = "/services/collector/health/1.0"
  87. protocol = "HTTPS"
  88. }
  89. }
  90. # Attach the instnaces to the ELB
  91. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  92. for_each = toset([ module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0] ])
  93. alb_target_group_arn = aws_lb_target_group.hec_8088.arn
  94. autoscaling_group_name = each.key
  95. }