Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions edge-terraform-router/modules/service-vcl/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}
28 changes: 28 additions & 0 deletions edge-terraform-router/modules/service-vcl/vcl-service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions edge-terraform-router/prod-delivery/main.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions edge-terraform-router/prod-delivery/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
}
Loading