Hi, I’m getting this error - invalid value for “inputMap” parameter: lookup() requires a map as the first argument.
I’m creating WAFv2 web acl and rules for the acl.
Snippert of my module look like this:
terraform {
required_version = ">= 1.0.3"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
module "wafv2" {
source = "terraform-aws-waf.git?ref=v0.0.5"
web_acl_name = "defect-dojo-wafv2"
scope = "REGIONAL"
allow_default_action = true
create_alb_association = true"
enabled = true
name_prefix = "defect-dojo"
visibility_config = {
metric_name = "defect-dojo"
}
rules = {
name = "defect-dojo"
priority = "1"
action = "count"
visibility_config = {
cloudwatch_metrics_enabled = false
metric_name = "defect-dojo"
sampled_requests_enabled = false
}
byte_match_statement = {
field_to_match = {
uri_path = "{}"
}
positional_constraint = "STARTS_WIH"
search_string = "/portal"
priority = 0
type = "NONE"
}
}
}
resource "aws_wafv2_web_acl" "waf_web_acl" {
count = var.enabled ? 1 : 0
name = local.waf_web_acl_name
scope = var.scope
description = var.description
default_action {
dynamic "allow" {
for_each = var.allow_default_action ? [1] : []
content {}
}
dynamic "block" {
for_each = var.allow_default_action ? [1] : []
content {}
}
}
dynamic "rule" {
for_each = var.rules
content {
name = lookup(rule.value, "name")
priority = lookup(rule.value, "priority")
dynamic "action" {
for_each = length(lookup(rule.value, "action", {})) == 0 ? [] : [1]
content {
dynamic "allow" {
for_each = lookup(rule.value, "action", {}) == "allow" ? [1] : []
content {}
}
dynamic "block" {
for_each = lookup(rule.value, "action", {}) == "block" ? [1] : []
content {}
}
dynamic "count" {
for_each = lookup(rule.value, "action", {}) == "count" ? [1] : []
content {}
}
}
}
dynamic "override_action" {
for_each = length(lookup(rule.value, "override_action", {})) == 0 ? [] : [1]
content {
dynamic "none" {
for_each = lookup(rule.value, "override_action", {}) == "none" ? [1] : []
content {}
}
dynamic "count" {
for_each = lookup(rule.value, "override_action", {}) == "count" ? [1] : []
content {}
}
}
}
statement {
dynamic "byte_match_statement" {
for_each = length(lookup(rule.value, "byte_match_statement", {})) == 0 ? [] : [lookup(rule.value, "byte_match_statement", {})]
content {
dynamic "field_to_match" {
for_each = length(lookup(byte_match_statement.value, "field_to_match", {})) == 0 ? [] : [lookup(byte_match_statement.value, "field_to_match", {})]
content {
dynamic "uri_path" {
for_each = length(lookup(field_to_match.value, "uri_path", {})) == 0 ? [] : [lookup(field_to_match.value, "uri_path")]
content {}
}
dynamic "query_string" {
for_each = length(lookup(field_to_match.value, "query_string", {})) == 0 ? [] : [lookup(field_to_match.value, "query_string")]
content {}
}
dynamic "all_query_arguments" {
for_each = length(lookup(field_to_match.value, "all_query_arguments", {})) == 0 ? [] : [lookup(field_to_match.value, "all_query_arguments")]
content {}
}
}
}
positional_constraint = lookup(byte_match_statement.value, "positional_constraint")
search_string = lookup(byte_match_statement.value, "search_string")
text_transformation {
priority = lookup(byte_match_statement.value, "priority")
type = lookup(byte_match_statement.value, "type")
}
}
}
dynamic "rate_based_statement" {
for_each = length(lookup(rule.value, "rate_based_statement", {})) == 0 ? [] : [lookup(rule.value, "rate_based_statement", {})]
content {
limit = lookup(rate_based_statement.value, "limit")
aggregate_key_type = lookup(rate_based_statement.value, "aggregate_key_type", "IP")
dynamic "forwarded_ip_config" {
for_each = length(lookup(rule.value, "forwarded_ip_config", {})) == 0 ? [] : [lookup(rule.value, "forwarded_ip_config", {})]
content {
fallback_behavior = lookup(forwarded_ip_config.value, "fallback_behavior")
header_name = lookup(forwarded_ip_config.value, "header_name")
}
}
}
}
}
variable "rules" {
description = "list of WAF rules"
type = any
default = []
}
the error message is below, i am not sure what i’m doing wrong:
on .terraform/modules/wafv2/main.tf line 35, in resource "aws_wafv2_web_acl" "waf_web_acl":
│ 35: for_each = length(lookup(rule.value, "action", {})) == 0 ? [] : [1]
│ ├────────────────
│ │ rule.value is "defect-dojo"
│
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵
╷
│ Error: Invalid function argument
│
│ on .terraform/modules/wafv2/main.tf line 35, in resource "aws_wafv2_web_acl" "waf_web_acl":
│ 35: for_each = length(lookup(rule.value, "action", {})) == 0 ? [] : [1]
│ ├────────────────
│ │ rule.value is "1"
│
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵
╷
│ Error: Invalid function argument
│
│ on .terraform/modules/wafv2/main.tf line 56, in resource "aws_wafv2_web_acl" "waf_web_acl":
│ 56: for_each = length(lookup(rule.value, "override_action", {})) == 0 ? [] : [1]
│ ├────────────────
│ │ rule.value is "count"
│
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵```