How do I chain to resource(s) created with count? Or should I not created them with count if I want to chain additional resources to them? Doing it the way below, with count used in the initial resource and for_each used in the chained resource gives me the following error:
The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type number.
I understand why this error occurs, but I also am confused on the best practice here.
resource "aws_wafv2_web_acl" "waf_acl_regional" {
count = var.env == "prod" ? 1 : 0
name = "${var.project}-${var.env}"
description = "A simple WAF ACL for ${var.env} environment."
scope = "REGIONAL"
default_action {
allow {}
}
rule {
...
}
visibility_config {
...
}
}
resource "aws_wafv2_web_acl_association" "example" {
for_each = aws_wafv2_web_acl.waf_acl_regional
resource_arn = aws_lb.hasura.arn
web_acl_arn = each.value.arn
}
Thanks for any help!