umotif-public / terraform-aws-waf-webaclv2

Terraform module to configure WAF V2 Web ACL with managed rules for Application Load Balancer
https://registry.terraform.io/modules/umotif-public/waf-webaclv2/aws
Other
140 stars 126 forks source link

4.x release returns error when `enabled` is false. #91

Open davidjeddy opened 1 year ago

davidjeddy commented 1 year ago

What is the current behavior?

Failing to plan if enabled set to (bool)false. Using 3.x the error does not happen.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

module "public_api_cdn" {
  source  = "source_url"
  version = "4.1.2"

  alb_arn     = aws_lb_listener.public_api_https.arn
  enabled     = false // tobool(var.feature_toggles.waf)
  name_prefix = join(var.delimiter, [var.environment, var.application, var.random_string, ])

  visibility_config = {
    cloudwatch_metrics_enabled = false
    metric_name                = join(var.delimiter, [var.environment, var.application, "waf", "metric", "public", "api", var.random_string])
    sampled_requests_enabled   = false
  }
}
terraform init
...
terraform plan
...
│ Error: Invalid index
│ 
│   on .terraform/modules/public_api_cdn/outputs.tf line 28, in output "web_acl_rule_names":
│   28:   value       = [for rule_names in aws_wafv2_web_acl.main[0].rule : rule_names.name if var.enabled]
│     ├────────────────
│     │ aws_wafv2_web_acl.main is empty tuple
│ 
│ The given key does not identify an element in this collection value: the collection has no elements.
╵

What is the expected behavior?

TF plan should exit successfully. The outputs should be wrapped to support dis/enabled resources.

The output sh

Software versions?

david:nygw$ terraform --version
Terraform v1.3.9
on linux_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v4.57.0
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/random v3.4.3
+ provider registry.terraform.io/hashicorp/template v2.2.0
+ provider registry.terraform.io/hashicorp/tls v4.0.3
PLeS207 commented 1 year ago

faced with the same issue

thicksR40 commented 1 year ago

Having the same issue on running env and new Terraform v1.5.4 aws v4.44.0

mjmayer commented 2 weeks ago

Issue still exist in waf-webaclv2 version 5.1.2