elb-with-acks.tf 6.2 KB

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