elb-private.tf 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. lifecycle {
  23. create_before_destroy = true
  24. }
  25. tags = merge(var.standard_tags, var.tags)
  26. }
  27. resource "aws_acm_certificate_validation" "hec_pvt_cert_validation" {
  28. count = var.splunk_private_hec ? 1 : 0
  29. certificate_arn = aws_acm_certificate.hec_pvt_cert[count.index].arn
  30. validation_record_fqdns = [for record in aws_route53_record.hec_pvt_cert_validation: record.fqdn] # will be empty if not moose
  31. }
  32. resource "aws_route53_record" "hec_pvt_cert_validation" {
  33. provider = aws.mdr-common-services-commercial
  34. for_each = ( var.splunk_private_hec ? {
  35. for dvo in aws_acm_certificate.hec_pvt_cert[0].domain_validation_options: dvo.domain_name => {
  36. name = dvo.resource_record_name
  37. record = dvo.resource_record_value
  38. type = dvo.resource_record_type
  39. }
  40. } : {}
  41. )# Empty map if not moose
  42. allow_overwrite = true
  43. name = each.value.name
  44. records = [each.value.record]
  45. ttl = 60
  46. type = each.value.type
  47. zone_id = var.dns_info["public"]["zone_id"]
  48. }
  49. #########################
  50. # ELB
  51. resource "aws_lb" "hec_pvt" {
  52. count = var.splunk_private_hec ? 1 : 0
  53. tags = merge(var.standard_tags, var.tags)
  54. name = "${var.prefix}-hec-private"
  55. load_balancer_type = "application"
  56. security_groups = [ aws_security_group.hec_pvt_elb_security_group[0].id ]
  57. subnets = var.private_subnets
  58. internal = true
  59. }
  60. resource "aws_lb_listener" "hec_pvt_443" {
  61. count = var.splunk_private_hec ? 1 : 0
  62. load_balancer_arn = aws_lb.hec_pvt[0].arn
  63. port = 443
  64. protocol = "HTTPS"
  65. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  66. certificate_arn = aws_acm_certificate.hec_pvt_cert[0].arn
  67. default_action {
  68. type = "forward"
  69. target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  70. }
  71. }
  72. resource "aws_lb_listener" "hec_pvt_8088" {
  73. count = var.splunk_private_hec ? 1 : 0
  74. load_balancer_arn = aws_lb.hec_pvt[0].arn
  75. port = 8088
  76. protocol = "HTTPS"
  77. ssl_policy = "ELBSecurityPolicy-TLS-1-2-2017-01"
  78. certificate_arn = aws_acm_certificate.hec_pvt_cert[0].arn
  79. default_action {
  80. type = "forward"
  81. target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  82. }
  83. }
  84. resource "aws_lb_target_group" "hec_pvt_8088" {
  85. count = var.splunk_private_hec ? 1 : 0
  86. name = "${var.prefix}-hec-pvt-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 instances to the ELB
  97. resource "aws_autoscaling_attachment" "hec_pvt_asg_attachments" {
  98. for_each = var.splunk_private_hec ? toset([ module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0] ]) : []
  99. alb_target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  100. autoscaling_group_name = each.key
  101. }