Skip to content

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

Open
@davidjeddy

Description

@davidjeddy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions