title: for_each value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created
body: <p>i am trying to create route 53 using module concept. but getting below error.
  &quot;The &quot;for_each&quot; value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created.&quot;
  for_each = var.create-route53 ? local.recordsets : tomap({})</p>
  <p><strong>local.recordsets will be known only after apply</strong>
  var.create-route53 is true</p>
  <p>can someone guide me on this ?</p>
  <p>actual code:</p>
  <pre><code>module &quot;route53&quot; {
  ...
  ...
    records = [
      {
        name    = &quot;test-name&quot;
        type    = &quot;A&quot;
        ttl     = 300
        records = [for instance in module.ec2: instance.ec2-IP      
        ]
      },
    ]
    vpc_id = &quot;${module.vpc.vpc_id}&quot;
  } 
  
  Inside modules folder below code will be there in route53 folder:
  
  locals {
    records = try(jsondecode(var.records), var.records)
     recordsets = {
      for rs in local.records :
      join(&quot; &quot;, compact([&quot;${rs.name} ${rs.type}&quot;, lookup(rs, &quot;set_identifier&quot;, &quot;&quot;)])) =&gt; merge(rs, {
        records = jsonencode(try(rs.records, null))
      })
    }
  }
  
  resource &quot;aws_route53_record&quot; &quot;this&quot; {
    for_each = var.create-route53 ? local.recordsets : tomap({})
    zone_id = aws_route53_zone.private.zone_id
    name                             = each.value.name != &quot;&quot; ? &quot;${each.value.name}&quot; : &quot;test&quot;
    type                             = each.value.type
    ttl                              = lookup(each.value, &quot;ttl&quot;, null)
    records                          = jsondecode(each.value.records)
    set_identifier                   = lookup(each.value, &quot;set_identifier&quot;, null)
    health_check_id                  = lookup(each.value, &quot;health_check_id&quot;, null)
    multivalue_answer_routing_policy = lookup(each.value, &quot;multivalue_answer_routing_policy&quot;, null)
    allow_overwrite                  = lookup(each.value, &quot;allow_overwrite&quot;, false)
  }
  </code></pre>