elb-with-acks.tf 5.8 KB

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