lb.tf 3.5 KB

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