title: How to use notification channels created via terraform into alert policies with for_each
body: <p>I am creating gcp notification channels using terraform
  example :notification_channels.tf</p>
  <pre><code>resource &quot;google_monitoring_notification_channel&quot; &quot;alert_notification_opsgenie_channel&quot; {
    for_each = { for inst in var.notification_channels : inst.display_name =&gt; inst }
    display_name = each.value.display_name
    type = &quot;webhook_tokenauth&quot;
    labels = {
      &quot;url&quot; = each.value.url
    }
    enabled = each.value.enabled
  }
  </code></pre>
  <p>I have to use these created notification channels in configuring gcp alert policies</p>
  <p>example alert_policy.tf:</p>
  <pre><code>resource &quot;google_monitoring_alert_policy&quot; &quot;business_metric_alert_policy&quot; {
    for_each = { for inst in var.business_metric_alert_policies : inst.display_name =&gt; inst }
    display_name = each.value.display_name
    combiner = &quot;OR&quot;
    conditions {
      display_name = each.value.condition_display_name
      condition_threshold {
        filter = each.value.filter
        duration = each.value.duration
        comparison = each.value.comparison
        threshold_value = each.value.threshold_value
        trigger {
            count = each.value.trigger_count
        }
        aggregations {
          alignment_period = each.value.alignment_period
          per_series_aligner = each.value.per_series_aligner
          cross_series_reducer = each.value.cross_series_reducer
        }
      }
    }
    notification_channels = &lt;&lt; how to get notification channels here &gt;&gt;
  }
  </code></pre>
  <p>this creates multiple alert policy resources, which may contain any number of notification channels.</p>