elb-private.tf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 = local.splunk_private_hec ? true : false
  9. name = "${var.prefix}-hec"
  10. target_dns_names = local.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 = local.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(local.standard_tags, var.tags)
  26. }
  27. resource "aws_acm_certificate_validation" "hec_pvt_cert_validation" {
  28. count = local.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 = (local.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 = local.splunk_private_hec ? 1 : 0
  53. tags = merge(local.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. drop_invalid_header_fields = true
  60. }
  61. resource "aws_lb_listener" "hec_pvt_443" {
  62. count = local.splunk_private_hec ? 1 : 0
  63. load_balancer_arn = aws_lb.hec_pvt[0].arn
  64. port = 443
  65. protocol = "HTTPS"
  66. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  67. certificate_arn = aws_acm_certificate.hec_pvt_cert[0].arn
  68. default_action {
  69. type = "forward"
  70. target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  71. }
  72. }
  73. resource "aws_lb_listener" "hec_pvt_8088" {
  74. count = local.splunk_private_hec ? 1 : 0
  75. load_balancer_arn = aws_lb.hec_pvt[0].arn
  76. port = 8088
  77. protocol = "HTTPS"
  78. ssl_policy = "ELBSecurityPolicy-FS-1-2-Res-2020-10" # PFS, TLS1.2, and GCM; most "restrictive" policy
  79. certificate_arn = aws_acm_certificate.hec_pvt_cert[0].arn
  80. default_action {
  81. type = "forward"
  82. target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  83. }
  84. }
  85. resource "aws_lb_target_group" "hec_pvt_8088" {
  86. count = local.splunk_private_hec ? 1 : 0
  87. name = "${var.prefix}-hec-pvt-targets"
  88. port = 8088
  89. protocol = "HTTPS"
  90. target_type = "instance"
  91. vpc_id = var.vpc_id
  92. health_check {
  93. path = "/services/collector/health/1.0"
  94. protocol = "HTTPS"
  95. }
  96. }
  97. # Attach the instances to the ELB
  98. resource "aws_autoscaling_attachment" "hec_pvt_asg_attachments" {
  99. for_each = local.splunk_private_hec ? toset([module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0]]) : []
  100. lb_target_group_arn = aws_lb_target_group.hec_pvt_8088[0].arn
  101. autoscaling_group_name = each.key
  102. }