elb-with-acks.tf 6.0 KB

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