elb-without-ack.tf 3.3 KB

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