elb-private.tf 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #------------------------------------------------------------------------------
  2. # An external ALB for the indexers for HEC
  3. #------------------------------------------------------------------------------
  4. #########################
  5. # DNS Entry
  6. module "private_dns_record_hec_pvt" {
  7. source = "../../../submodules/dns/private_CNAME_record"
  8. enabled = var.splunk_private_hec ? true : false
  9. name = "${var.prefix}-hec"
  10. target_dns_names = var.splunk_private_hec ? [ aws_lb.hec_pvt[0].dns_name ] : [ "na" ]
  11. dns_info = var.dns_info
  12. providers = {
  13. aws.c2 = aws.c2
  14. }
  15. }
  16. #########################
  17. # Certificate - NOTE: Public certificate for a private HEC
  18. resource "aws_acm_certificate" "hec_pvt_cert" {
  19. count = var.splunk_private_hec ? 1 : 0
  20. domain_name = "${var.prefix}-hec.${var.dns_info["private"]["zone"]}"
  21. validation_method = "DNS"
  22. tags = merge(var.standard_tags, var.tags)
  23. }
  24. resource "aws_acm_certificate_validation" "hec_pvt_cert_validation" {
  25. count = var.splunk_private_hec ? 1 : 0
  26. certificate_arn = aws_acm_certificate.hec_pvt_cert[count.index].arn
  27. validation_record_fqdns = [for record in aws_route53_record.hec_pvt_cert_validation: record.fqdn] # will be empty if not moose
  28. }
  29. resource "aws_route53_record" "hec_pvt_cert_validation" {
  30. provider = aws.mdr-common-services-commercial
  31. for_each = ( var.splunk_private_hec ? {
  32. for dvo in aws_acm_certificate.hec_pvt_cert[0].domain_validation_options: dvo.domain_name => {
  33. name = dvo.resource_record_name
  34. record = dvo.resource_record_value
  35. type = dvo.resource_record_type
  36. }
  37. } : {}
  38. )# Empty map if not moose
  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_pvt" {
  49. count = var.splunk_private_hec ? 1 : 0
  50. tags = merge(var.standard_tags, var.tags)
  51. name = "${var.prefix}-hec-private"
  52. load_balancer_type = "application"
  53. security_groups = [ aws_security_group.hec_pvt_elb_security_group[0].id ]
  54. subnets = var.private_subnets
  55. internal = true
  56. }
  57. resource "aws_lb_listener" "hec_pvt_443" {
  58. count = var.splunk_private_hec ? 1 : 0
  59. load_balancer_arn = aws_lb.hec_pvt[0].arn
  60. port = 443
  61. protocol = "HTTPS"
  62. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  63. certificate_arn = aws_acm_certificate.hec_pvt_cert[0].arn
  64. default_action {
  65. type = "forward"
  66. target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  67. }
  68. }
  69. resource "aws_lb_listener" "hec_pvt_8088" {
  70. count = var.splunk_private_hec ? 1 : 0
  71. load_balancer_arn = aws_lb.hec_pvt[0].arn
  72. port = 8088
  73. protocol = "HTTPS"
  74. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  75. certificate_arn = aws_acm_certificate.hec_pvt_cert[0].arn
  76. default_action {
  77. type = "forward"
  78. target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  79. }
  80. }
  81. resource "aws_lb_target_group" "hec_pvt_8088" {
  82. count = var.splunk_private_hec ? 1 : 0
  83. name = "${var.prefix}-hec-pvt-targets"
  84. port = 8088
  85. protocol = "HTTPS"
  86. target_type = "instance"
  87. vpc_id = var.vpc_id
  88. health_check {
  89. path = "/services/collector/health/1.0"
  90. protocol = "HTTPS"
  91. }
  92. }
  93. # Attach the instances to the ELB
  94. resource "aws_autoscaling_attachment" "hec_pvt_asg_attachments" {
  95. for_each = var.splunk_private_hec ? toset([ module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0] ]) : []
  96. alb_target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  97. autoscaling_group_name = each.key
  98. }