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