elb-with-acks.tf 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #------------------------------------------------------------------------------
  2. # An external ELB for the indexers for HEC, because acknowledgements
  3. #------------------------------------------------------------------------------
  4. #########################
  5. # DNS Entry
  6. module "public_dns_record_hec_ack" {
  7. source = "../../../submodules/dns/public_ALIAS_record"
  8. name = "${var.prefix}-hec-ack"
  9. target_dns_name = aws_elb.hec_classiclb.dns_name
  10. target_zone_id = aws_elb.hec_classiclb.zone_id
  11. dns_info = var.dns_info
  12. providers = {
  13. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  14. }
  15. }
  16. #########################
  17. # Certificate
  18. resource "aws_acm_certificate" "hec_classiclb_cert" {
  19. domain_name = "${var.prefix}-hec-ack.${var.dns_info["public"]["zone"]}"
  20. validation_method = "DNS"
  21. tags = merge(var.standard_tags, var.tags)
  22. }
  23. resource "aws_acm_certificate_validation" "hec_classiclb_cert_validation" {
  24. certificate_arn = aws_acm_certificate.hec_classiclb_cert.arn
  25. validation_record_fqdns = [for record in aws_route53_record.hec_classiclb_cert_validation: record.fqdn]
  26. }
  27. resource "aws_route53_record" "hec_classiclb_cert_validation" {
  28. provider = aws.mdr-common-services-commercial
  29. for_each = {
  30. for dvo in aws_acm_certificate.hec_classiclb_cert.domain_validation_options : dvo.domain_name => {
  31. name = dvo.resource_record_name
  32. record = dvo.resource_record_value
  33. type = dvo.resource_record_type
  34. }
  35. }
  36. allow_overwrite = true
  37. name = each.value.name
  38. records = [each.value.record]
  39. ttl = 60
  40. type = each.value.type
  41. zone_id = var.dns_info["public"]["zone_id"]
  42. }
  43. #########################
  44. # ELB
  45. resource "aws_elb" "hec_classiclb" {
  46. tags = merge(var.standard_tags, var.tags)
  47. name = "${var.prefix}-hec-classic"
  48. security_groups = [ aws_security_group.hec_elb_security_group.id ]
  49. subnets = var.public_subnets
  50. internal = false
  51. listener {
  52. instance_port = 8088
  53. instance_protocol = "https"
  54. lb_port = 8088
  55. lb_protocol = "https"
  56. ssl_certificate_id = aws_acm_certificate.hec_classiclb_cert.arn
  57. }
  58. listener {
  59. instance_port = 8088
  60. instance_protocol = "https"
  61. lb_port = 443
  62. lb_protocol = "https"
  63. ssl_certificate_id = aws_acm_certificate.hec_classiclb_cert.arn
  64. }
  65. health_check {
  66. healthy_threshold = 10
  67. unhealthy_threshold = 2
  68. timeout = 5
  69. target = "HTTPS:8088/services/collector/health/1.0"
  70. interval = 30
  71. }
  72. access_logs {
  73. bucket = "xdr-elb-${ var.environment }"
  74. enabled = true
  75. }
  76. }
  77. # AWS Firehose / Splunk requirement for ELB cookies to have
  78. # cookie_expiration_period=0. Terraform does not support that directly
  79. # and expects >=1. Not specifying an expiration period causes a period
  80. # of 0. See https://github.com/terraform-providers/terraform-provider-aws/issues/12678
  81. resource "aws_lb_cookie_stickiness_policy" "hec_classiclb_sticky_443" {
  82. name = "sticky443-2"
  83. load_balancer = aws_elb.hec_classiclb.id
  84. lb_port = 443
  85. }
  86. # AWS Firehose / Splunk requirement for ELB cookies to have
  87. # cookie_expiration_period=0. Terraform does not support that directly
  88. # and expects >=1. Not specifying an expiration period causes a period
  89. # of 0. See https://github.com/terraform-providers/terraform-provider-aws/issues/12678
  90. resource "aws_lb_cookie_stickiness_policy" "hec_classiclb_sticky_8088" {
  91. name = "sticky8088"
  92. load_balancer = aws_elb.hec_classiclb.id
  93. lb_port = 8088
  94. }
  95. # Attach the instnaces to the ELB
  96. resource "aws_autoscaling_attachment" "hec_classic_asg_attachments" {
  97. for_each = toset([ module.indexer0.asg_name[0], module.indexer1.asg_name[0], module.indexer2.asg_name[0] ])
  98. elb = aws_elb.hec_classiclb.id
  99. autoscaling_group_name = each.key
  100. }
  101. # See https://github.com/terraform-providers/terraform-provider-aws/issues/995
  102. resource "aws_load_balancer_policy" "listener_policy-tls-1-2" {
  103. load_balancer_name = aws_elb.hec_classiclb.name
  104. policy_name = "elb-tls-1-2"
  105. policy_type_name = "SSLNegotiationPolicyType"
  106. policy_attribute {
  107. name = "Reference-Security-Policy"
  108. value = "ELBSecurityPolicy-TLS-1-2-2017-01"
  109. }
  110. # Workaround for bug above. If changing TLS policy then be
  111. # prepared to taint the resource. Tested/working taint commands
  112. # (as of 2020-06-25) are:
  113. # terraform taint --module customer.indexer_cluster aws_load_balancer_policy.listener_policy-tls-1-2
  114. # terraform taint --module customer.indexer_cluster aws_load_balancer_listener_policy.hec_classiclb_listener_443
  115. # terraform taint --module customer.indexer_cluster aws_load_balancer_listener_policy.hec_classiclb_listener_8088
  116. #
  117. # As of this time, w/ terraform 0.11.14, you have to taint all three
  118. # to effect a change here.
  119. #
  120. # 2020-11-04 - Confirmed this is still a bug in 0.13
  121. lifecycle {
  122. ignore_changes = [ policy_attribute ]
  123. }
  124. }
  125. # Have to make sure to add the sticky policy here too or it causes
  126. # the listener to lose the sticky policy set above and terraform
  127. # attempts to re-add it on each apply run
  128. resource "aws_load_balancer_listener_policy" "hec_classiclb_listener_443" {
  129. load_balancer_name = aws_elb.hec_classiclb.name
  130. load_balancer_port = 443
  131. policy_names = [
  132. aws_load_balancer_policy.listener_policy-tls-1-2.policy_name,
  133. aws_lb_cookie_stickiness_policy.hec_classiclb_sticky_443.name,
  134. ]
  135. }
  136. # Have to make sure to add the sticky policy here too or it causes
  137. # the listener to lose the sticky policy set above and terraform
  138. # attempts to re-add it on each apply run
  139. resource "aws_load_balancer_listener_policy" "hec_classiclb_listener_8088" {
  140. load_balancer_name = aws_elb.hec_classiclb.name
  141. load_balancer_port = 8088
  142. policy_names = [
  143. aws_load_balancer_policy.listener_policy-tls-1-2.policy_name,
  144. aws_lb_cookie_stickiness_policy.hec_classiclb_sticky_8088.name,
  145. ]
  146. }