elb-without-ack.tf 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. tags = merge(var.standard_tags, var.tags)
  22. }
  23. resource "aws_acm_certificate_validation" "hec_cert_validation" {
  24. certificate_arn = aws_acm_certificate.hec_cert.arn
  25. validation_record_fqdns = [for record in aws_route53_record.hec_cert_validation: record.fqdn]
  26. }
  27. resource "aws_route53_record" "hec_cert_validation" {
  28. provider = aws.mdr-common-services-commercial
  29. for_each = {
  30. for dvo in aws_acm_certificate.hec_cert.domain_validation_options : dvo.domain_name => {
  31. name = dvo.resource_record_name
  32. record = dvo.resource_record_value
  33. type = dvo.resource_record_type
  34. }
  35. }
  36. allow_overwrite = true
  37. name = each.value.name
  38. records = [each.value.record]
  39. ttl = 60
  40. type = each.value.type
  41. zone_id = var.dns_info["public"]["zone_id"]
  42. }
  43. #########################
  44. # ELB
  45. resource "aws_lb" "hec" {
  46. tags = merge(var.standard_tags, var.tags)
  47. name = "${var.prefix}-hec"
  48. load_balancer_type = "application"
  49. security_groups = [ aws_security_group.hec_elb_security_group.id ]
  50. subnets = var.public_subnets
  51. internal = false
  52. }
  53. resource "aws_lb_listener" "hec_443" {
  54. count = local.is_moose ? 1 : 0
  55. load_balancer_arn = aws_lb.hec.arn
  56. port = 443
  57. protocol = "HTTPS"
  58. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  59. certificate_arn = aws_acm_certificate.hec_cert.arn
  60. default_action {
  61. type = "forward"
  62. target_group_arn = aws_lb_target_group.hec_8088.arn
  63. }
  64. }
  65. resource "aws_lb_listener" "hec_8088" {
  66. load_balancer_arn = aws_lb.hec.arn
  67. port = 8088
  68. protocol = "HTTPS"
  69. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  70. certificate_arn = aws_acm_certificate.hec_cert.arn
  71. default_action {
  72. type = "forward"
  73. target_group_arn = aws_lb_target_group.hec_8088.arn
  74. }
  75. }
  76. resource "aws_lb_target_group" "hec_8088" {
  77. name = "${var.prefix}-hec-targets"
  78. port = 8088
  79. protocol = "HTTPS"
  80. target_type = "instance"
  81. vpc_id = var.vpc_id
  82. health_check {
  83. path = "/services/collector/health/1.0"
  84. protocol = "HTTPS"
  85. }
  86. }
  87. # Attach the instnaces to the ELB
  88. resource "aws_autoscaling_attachment" "hec_asg_attachments" {
  89. for_each = toset([ module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0] ])
  90. alb_target_group_arn = aws_lb_target_group.hec_8088.arn
  91. autoscaling_group_name = each.key
  92. }