lgallard / terraform-aws-route53-resolver-rules

Terraform module to create AWS Route53 Resolver Rules.
Apache License 2.0
9 stars 12 forks source link

Issue: "Cannot use a null value in for_each" when not specifying "ips" #11

Open nnt opened 3 years ago

nnt commented 3 years ago

Source code

module "resolver_rule_name" {
  source               = "git::https://github.com/lgallard/terraform-aws-route53-resolver-rules.git"
  resolver_endpoint_id = aws_route53_resolver_endpoint.inbound_endpoint_name.id

  rules = [
    {
      domain_name = "example.com"
      vpc_ids     = [ids-go-here]
      principals  = [account-ids-go-here]
    }
  ]
}

Error

Error: Invalid dynamic for_each value

  on .terraform/modules/resolver_rule_name/main.tf line 12, in resource "aws_route53_resolver_rule" "r":
  12:     for_each = lookup(element(local.rules, count.index), "ips", [])
    |----------------
    | count.index is 1
    | local.rules is tuple with 2 elements

Cannot use a null value in for_each.

More information

My guess is that the error is caused by the lack of ips in each rule, which I am not sure why is required in this module (the resource route53_resolver_rule makes this optional). Maybe the author wrote this module with external/on-prem DNS in mind?

lgallard commented 3 years ago

@nnt first off, sorry about the delay. I hadn't' seen this issue before.

Nw regarding the issue, you could seth ips has empty list and it should work:

module "resolver_rule_name" {
  source               = "git::https://github.com/lgallard/terraform-aws-route53-resolver-rules.git"
  resolver_endpoint_id = aws_route53_resolver_endpoint.inbound_endpoint_name.id

  rules = [
    {
      domain_name = "example.com"
      vpc_ids     = [ids-go-here]
      principals  = [account-ids-go-here]
      ips         = []
    }
  ]
}