elb-with-acks.tf 6.3 KB

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