title: Terraform module output to use as input in other module specifically with for_each
body: <p>I need some guidance on below use case. I have one stack that has 30 aws target groups to create. So I am using a module with for_each with diff paramters and creating 30 Target groups. Now Later I need to create 30 listener forwarding rules where I have to pass output of above target group's arn. I am getting error that string required. I am sure output is a string and it works when I call module multiple time without for_each.</p>
  <pre><code>    module &quot;listener_rule_Models&quot; {
    source = &quot;git::https://mycompany/_git/terraform-aws-alb-listener-rule&quot;
      for_each = {
        &quot;models&quot; = {
          tg_arn = module.tgLOGIN[&quot;MODELS&quot;].tg_arn
          forwarding_path = [&quot;/my_service.application_path*&quot;]
        },
        &quot;indexEngine&quot; = {
          tg_arn = module.tgLOGIN[&quot;MODELS&quot;].tg_arn
          forwarding_path = [&quot;/my_service2.application_path*&quot;]
        }
      }
    listener_arn = module.lis-Consolidated81.listener_arn
    tg_arn       = each.value
    forwarding_path = [each.value]
  }
  </code></pre>
  <p>Error :  Invalid value for module argument</p>
  <p>on main.tf line 181, in module &quot;listener_rule_Models&quot;:
  181:   tg_arn       = each.value</p>
  <p>The given value is not suitable for child module variable &quot;tg_arn&quot; defined at
  .terraform\modules\listener_rule_Models\variables.tf:6,1-18: string required.</p>
  <p>Error: Invalid value for module argument</p>
  <p>on main.tf line 181, in module &quot;listener_rule_Models&quot;:
  181:   tg_arn       = each.value</p>
  <p>The given value is not suitable for child module variable &quot;tg_arn&quot; defined at
  .terraform\modules\listener_rule_Models\variables.tf:6,1-18: string required.</p>
  <p>Error: Invalid value for module argument</p>
  <p>on main.tf line 182, in module &quot;listener_rule_Models&quot;:
  182:   forwarding_path = [each.value]</p>
  <p>The given value is not suitable for child module variable &quot;forwarding_path&quot;
  defined at .terraform\modules\listener_rule_Models\variables.tf:17,1-27:
  element 0: string required.</p>
  <p>Error: Invalid value for module argument</p>
  <p>on main.tf line 182, in module &quot;listener_rule_Models&quot;:
  182:   forwarding_path = [each.value]</p>