Skip to content

Commit

Permalink
PLT-894 - Add support for transform requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Engerim committed Jul 30, 2024
1 parent e32643a commit 176e12b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
20 changes: 20 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ resource "cloudflare_ruleset" "this" {
}
}
}

# http_request_transform
dynamic "uri" {
for_each = rules.value.action_parameters.uri[*]
content {
dynamic "path" {
for_each = uri.value.path[*]
content {
value = path.value
}
}

dynamic "query" {
for_each = uri.value.query[*]
content {
value = query.value
}
}
}
}
}
}
description = rules.value.description
Expand Down
14 changes: 13 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ variable "rules" {
score_threshold = optional(number)
})), [])
}), null)

# phase: http_request_transform
uri = optional(object({
path = optional(string)
query = optional(string)
}))
}), null)
description = optional(string)
enabled = optional(bool, true)
Expand All @@ -110,7 +116,7 @@ variable "rules" {
# Ensure we specify only the supported action values
# https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/ruleset#action
validation {
condition = alltrue([for rule in var.rules : contains(["block", "challenge", "execute", "js_challenge", "log", "log_custom_field", "managed_challenge", "redirect", "route", "set_config", "skip"], rule.action)])
condition = alltrue([for rule in var.rules : contains(["block", "challenge", "execute", "js_challenge", "log", "log_custom_field", "managed_challenge", "redirect", "route", "set_config", "skip", "rewrite"], rule.action)])
error_message = "Only the following action elements are allowed: block, challenge, execute, js_challenge, log, managed_challenge, redirect, route, skip."
}

Expand Down Expand Up @@ -145,4 +151,10 @@ variable "rules" {
condition = alltrue([for rule in var.rules : try(contains(["off", "lossless", "lossy"], rule.action_parameters.polish), true)])
error_message = "Only the following polish elements are allowed off, lossless, lossy"
}

# Ensure that either query or path are set for rewrite rules
validation {
condition = alltrue([for rule in var.rules : rule.action == "rewrite" ? (can(rule.action_parameters.uri.path) || can(rule.action_parameters.uri.query)) : true])
error_message = "action_parameters.uri needs to have either path or query value for rewrite"
}
}

0 comments on commit 176e12b

Please sign in to comment.