elb.tf 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. module "elb" {
  2. source = "../../submodules/load_balancer/static_nlb_to_alb"
  3. name = "sensu"
  4. target_ids = [aws_instance.instance.id]
  5. listener_port = 443
  6. target_port = 8081
  7. target_protocol = "HTTPS"
  8. target_security_group = aws_security_group.instance_security_group.id
  9. allow_from_any = false
  10. # WAF variables
  11. waf_enabled = true
  12. #excluded_rules_AWSManagedRulesCommonRuleSet = [ "SizeRestrictions_BODY" ]
  13. #excluded_rules_AWSManagedRulesAmazonIpReputationList = []
  14. #excluded_rules_AWSManagedRulesKnownBadInputsRuleSet = []
  15. #excluded_rules_AWSManagedRulesSQLiRuleSet = []
  16. #excluded_rules_AWSManagedRulesLinuxRuleSet = []
  17. #excluded_rules_AWSManagedRulesUnixRuleSet = []
  18. #additional_blocked_ips = []
  19. #allowed_ips = []
  20. #admin_ips = []
  21. # Optional Variables
  22. healthcheck_port = 8080
  23. healthcheck_protocol = "HTTPS"
  24. healthcheck_path = "/health"
  25. healthcheck_matcher = "200"
  26. stickiness = false
  27. # Inherited Variables
  28. tags = merge(local.standard_tags, var.tags)
  29. dns_info = var.dns_info
  30. public_subnets = var.public_subnets
  31. environment = var.environment
  32. aws_partition = var.aws_partition
  33. aws_region = var.aws_region
  34. aws_account_id = var.aws_account_id
  35. vpc_id = var.vpc_id
  36. providers = {
  37. aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
  38. aws.c2 = aws.c2
  39. }
  40. }
  41. resource "aws_security_group_rule" "sensu-external-ips" {
  42. # This deserves some explanation. Terraform "for_each" expects to be
  43. # getting as input a map of values to iterate over as part of the foreach.
  44. # The keys of the map are used to name each of these objects created. Looking
  45. # in the terraform plan output of a for_each you'll see things like:
  46. #
  47. # aws_security_group_rule.resource_name["key-value-from-foreach"] will be created
  48. #
  49. # Our c2_services_external_ips is a list of maps, not a map of maps. The for-expression
  50. # makes a new thing that is a map of maps, where the key value is the description with
  51. # blanks removed.
  52. #
  53. # We could have made the variable more natively-friendly to for_each but this seemed
  54. # like a better solution for what we were trying to accomplish.
  55. for_each = { for s in local.c2_services_external_ips : replace(s.description, "/\\s*/", "") => s }
  56. description = "Sensu - ${each.value.description}"
  57. type = "ingress"
  58. from_port = 443
  59. to_port = 443
  60. protocol = "tcp"
  61. cidr_blocks = each.value.cidr_blocks # tfsec:ignore:aws-vpc-no-public-ingress-sgr Intentionally allow inbound
  62. security_group_id = module.elb.security_group_id
  63. }