title: Terraform correlation to resource with for_each
body: <p>I'm using below code to assign defualt subnets to ASG</p>
  <pre><code>resource &quot;aws_autoscaling_group&quot; &quot;ecs_spot_asg&quot; {
    for_each = data.aws_subnet_ids.all_subnets.ids
  .... etc...
  </code></pre>
  <p>Subnets done via</p>
  <pre><code>data &quot;aws_subnet_ids&quot; &quot;all_subnets&quot; {
    vpc_id = data.aws_vpc.default.id
  }
  </code></pre>
  <p>Below I have aws_autoscaling_policy and I'm stuck on how to relate one to the other</p>
  <pre><code>resource &quot;aws_autoscaling_policy&quot; &quot;ecs_cluster_scale_policy&quot; {
    autoscaling_group_name = aws_autoscaling_group.ecs_spot_asg.name
  </code></pre>
  <p>Getting error:</p>
  <blockquote>
  <p>Because aws_autoscaling_group.ecs_spot_asg has &quot;for_each&quot; set, its
  attributes must be accessed on specific instances.</p>
  <p>For example, to correlate with indices of a referring resource, use:
  aws_autoscaling_group.ecs_spot_asg[each.key]</p>
  </blockquote>
  <p>How this should be modified ?</p>