Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bubble up custom response body option #57

Closed
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ No modules.
| <a name="input_allow_default_action"></a> [allow\_default\_action](#input\_allow\_default\_action) | Set to `true` for WAF to allow requests by default. Set to `false` for WAF to block requests by default. | `bool` | `true` | no |
| <a name="input_create_alb_association"></a> [create\_alb\_association](#input\_create\_alb\_association) | Whether to create alb association with WAF web acl | `bool` | `true` | no |
| <a name="input_create_logging_configuration"></a> [create\_logging\_configuration](#input\_create\_logging\_configuration) | Whether to create logging configuration in order start logging from a WAFv2 Web ACL to Amazon Kinesis Data Firehose. | `bool` | `false` | no |
| <a name="input_custom_response_bodies"></a> [custom\_response\_bodies](#input\_custom\_response\_bodies) | https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl#custom-response-body | <pre>list(object({<br> key = string<br> content = string<br> content_type = string<br> }))</pre> | `[]` | no |
| <a name="input_description"></a> [description](#input\_description) | A friendly description of the WebACL | `string` | `null` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Whether to create the resources. Set to `false` to prevent the module from creating any resources | `bool` | `true` | no |
| <a name="input_log_destination_configs"></a> [log\_destination\_configs](#input\_log\_destination\_configs) | The Amazon Kinesis Data Firehose Amazon Resource Name (ARNs) that you want to associate with the web ACL. Currently, only 1 ARN is supported. | `list(string)` | `[]` | no |
Expand Down
26 changes: 25 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ resource "aws_wafv2_web_acl" "main" {
}
}

dynamic "custom_response_body" {
for_each = var.custom_response_bodies
content {
key = custom_response_body.value.key
content = custom_response_body.value.content
content_type = custom_response_body.value.content_type
}
}

dynamic "rule" {
for_each = var.rules
content {
Expand All @@ -43,7 +52,22 @@ resource "aws_wafv2_web_acl" "main" {

dynamic "block" {
for_each = lookup(rule.value, "action", {}) == "block" ? [1] : []
content {}
content {
dynamic "custom_response" {
for_each = lookup(rule.value, "custom_response", {}) != {} ? [1] : []
content {
custom_response_body_key = lookup(rule.value.custom_response, "custom_response_body_key", null)
response_code = rule.value.custom_response.response_code
dynamic "response_header" {
for_each = lookup(rule.value.custom_response, "response_headers", [])
content {
name = response_header.value.name
value = response_header.value.value
}
}
}
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ variable "description" {
description = "A friendly description of the WebACL"
default = null
}

variable "custom_response_bodies" {
type = list(object({
key = string
content = string
content_type = string
}))
description = "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/wafv2_web_acl#custom-response-body"
default = []
}