From 8e81115f9bbf90f35ed1d3997075f4d158b730c4 Mon Sep 17 00:00:00 2001 From: Jorge Falcon <22119513+BCTBB@users.noreply.github.com> Date: Thu, 2 Oct 2025 21:52:38 -0400 Subject: [PATCH] alb http listener rules processing fix (#115) - Added changes to handle additional conditions `host_headers`, `path_patterns`, `http_request_methods`, `source_ips`, `http_headers`, and `query_strings` --- byo-vpc/byo-db/main.tf | 29 +++++++++++++++++++++++++---- example/main.tf | 19 ++++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/byo-vpc/byo-db/main.tf b/byo-vpc/byo-db/main.tf index c593cbc..731ed82 100644 --- a/byo-vpc/byo-db/main.tf +++ b/byo-vpc/byo-db/main.tf @@ -102,10 +102,31 @@ module "alb" { } rules = { for idx, rule in var.alb_config.https_listener_rules : "rule-${idx}" => merge(rule, { - conditions = [for condition in rule.conditions : { - for k, v in condition : - "${trimsuffix(k, "s")}" => { values = v } - }] + conditions = flatten([ + for condition in rule.conditions : concat(flatten([ + for key in ["host_headers", "http_request_methods", "path_patterns", "source_ips"]: + lookup(condition, key, null) != null ? [{ + "${trimsuffix(key, "s")}" = { + values = condition[key] + } + }] : [] + ]), + lookup(condition, "http_headers", null) != null ? [ + for header in condition.http_headers : { + http_header = { + http_header_name = header.http_header_name + values = header.values + } + }]: [], + lookup(condition, "query_strings", null) != null ? [{ + query_string = [ + for qs in condition.query_strings : { + key = qs.key + value = qs.value + } + ] + }]: [], + )]) actions = [for action in rule.actions : merge(action, { target_group_key = try(action.target_group_key, try("tg-${action.target_group_index}", null)) })] diff --git a/example/main.tf b/example/main.tf index 871612d..2b022a9 100644 --- a/example/main.tf +++ b/example/main.tf @@ -73,7 +73,7 @@ locals { } module "fleet" { - source = "github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.18.2" + source = "github.com/fleetdm/fleet-terraform?depth=1&ref=tf-mod-root-v1.18.3" certificate_arn = module.acm.acm_certificate_arn vpc = { @@ -167,6 +167,23 @@ module "fleet" { # routing_http_response_x_frame_options_header_value = "SAMEORIGIN" # } # Optional rules to allowlist only osquery/orbit traffic and allowed IPs. + # For https_listener_rules, the following conditions are supported + # Example: + # conditions = [{ + # host_headers = ["example.com"] + # path_patterns = ["/api/*"] + # http_request_methods = ["GET", "POST"] + # source_ips = ["1.2.3.4/32"] + # http_headers = [{ + # http_header_name = "X-Custom-Header-Foo" + # values = ["bar"] + # }] + # query_strings = [{ + # key = "env" + # value = "foobar" + # }] + # }] + # # https_listener_rules = concat([{ # priority = 9000 # actions = [{