elb-without-ack.tf 3.0 KB

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