From bcb4005b96cab331f12889ebe6228ef2cde49c01 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 18:12:42 +0000 Subject: [PATCH 1/2] Initial plan From 6aabc949db821f4fc62476bd45098d4826498b6c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 31 Mar 2026 18:16:03 +0000 Subject: [PATCH 2/2] Add dynamic header block based on path via add_header_based_on_path variable Agent-Logs-Url: https://github.com/fastly/security-use-cases/sessions/89ca44d8-3889-4092-a301-46e601599557 Co-authored-by: BrooksCunningham <22921241+BrooksCunningham@users.noreply.github.com> --- .../modules/service-vcl/variables.tf | 10 +++++++ .../modules/service-vcl/vcl-service.tf | 28 +++++++++++++++++++ edge-terraform-router/prod-delivery/main.tf | 1 + .../prod-delivery/variables.tf | 10 +++++++ 4 files changed, 49 insertions(+) diff --git a/edge-terraform-router/modules/service-vcl/variables.tf b/edge-terraform-router/modules/service-vcl/variables.tf index a4611c5..7396edb 100644 --- a/edge-terraform-router/modules/service-vcl/variables.tf +++ b/edge-terraform-router/modules/service-vcl/variables.tf @@ -5,4 +5,14 @@ variable "fastly_routes" { origin_name = string })) default = [] +} + +variable "add_header_based_on_path" { + description = "A list of objects representing path-based header additions. If the request matches the path, the specified header is added." + type = list(object({ + path = string + header_name = string + header_value = string + })) + default = [] } \ No newline at end of file diff --git a/edge-terraform-router/modules/service-vcl/vcl-service.tf b/edge-terraform-router/modules/service-vcl/vcl-service.tf index c2f3be7..7789a01 100644 --- a/edge-terraform-router/modules/service-vcl/vcl-service.tf +++ b/edge-terraform-router/modules/service-vcl/vcl-service.tf @@ -42,5 +42,33 @@ resource "fastly_service_vcl" "edge-terraform-router-demo" { } } + # Iterates over the array to create path-based request conditions + dynamic "condition" { + for_each = var.add_header_based_on_path + content { + # Creates a unique condition name based on the path (e.g., "path-condition-anything-foo") + name = "path-condition-${replace(trimprefix(condition.value.path, "/"), "/", "-")}" + priority = 10 + # Evaluates the incoming request path against the path variable + statement = "req.url.path == \"${condition.value.path}\"" + type = "REQUEST" + } + } + + # Iterates over the array to add request headers based on path conditions + dynamic "header" { + for_each = var.add_header_based_on_path + content { + # Creates a unique header action name based on the header name and path + name = "header-${header.value.header_name}-${replace(trimprefix(header.value.path, "/"), "/", "-")}" + action = "set" + type = "request" + destination = "http.${header.value.header_name}" + source = "\"${header.value.header_value}\"" + # Links this header action to the corresponding path condition above + request_condition = "path-condition-${replace(trimprefix(header.value.path, "/"), "/", "-")}" + } + } + force_destroy = true } \ No newline at end of file diff --git a/edge-terraform-router/prod-delivery/main.tf b/edge-terraform-router/prod-delivery/main.tf index 260110f..d7ad562 100644 --- a/edge-terraform-router/prod-delivery/main.tf +++ b/edge-terraform-router/prod-delivery/main.tf @@ -1,6 +1,7 @@ module "service_vcl" { source = "../modules/service-vcl" fastly_routes = var.fastly_routes + add_header_based_on_path = var.add_header_based_on_path providers = { fastly = fastly diff --git a/edge-terraform-router/prod-delivery/variables.tf b/edge-terraform-router/prod-delivery/variables.tf index a4611c5..7396edb 100644 --- a/edge-terraform-router/prod-delivery/variables.tf +++ b/edge-terraform-router/prod-delivery/variables.tf @@ -5,4 +5,14 @@ variable "fastly_routes" { origin_name = string })) default = [] +} + +variable "add_header_based_on_path" { + description = "A list of objects representing path-based header additions. If the request matches the path, the specified header is added." + type = list(object({ + path = string + header_name = string + header_value = string + })) + default = [] } \ No newline at end of file