# Dependency graph bottleneck

**URL:** <https://discuss.hashicorp.com/t/dependency-graph-bottleneck/48057>\
**Category:** Terraform\
**Created:** [December 16, 2022, 10:55am UTC](https://discuss.hashicorp.com/t/dependency-graph-bottleneck/48057 "2022-12-16T10:55:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pszypowicz](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/pszypowicz/32/26286_2.png) [@pszypowicz](https://discuss.hashicorp.com/u/pszypowicz)\
**Post date:** [December 16, 2022, 10:55am UTC](https://discuss.hashicorp.com/t/dependency-graph-bottleneck/48057/1 "2022-12-16T10:55:27Z")

</div>

Hello,

I’m curious if there is a way to remove a bottle neck when you link resources.

I want to create a create `dns zone` and create a `dns zone link`. And I needed to add a sleep between (because of propagation of dns zones).

But the procedure looks like the following: Batch 1 (dns zone) → batch 2 (sleep) → batch 3 (links)

```auto
resource "azurerm_private_dns_zone" "dns_zone" {
  for_each = var.dns_zones

  name = each.value
  resource_group_name = var.resource_group_name
}

resource "time_sleep" "deploy_dns_zone" {
  for_each = var.dns_zones

  triggers = {
    id = azurerm_private_dns_zone.dns_zone[each.key].id
    name = azurerm_private_dns_zone.dns_zone[each.key].name
  }

  create_duration = "3m"
}

resource "azurerm_private_dns_zone_virtual_network_link" "dns_link" {
  for_each = var.dns_zones

  name = "dnsl-${each.value}"
  resource_group_name = var.resource_group_name
  private_dns_zone_name = time_sleep.deploy_dns_zone[each.key].triggers.name
  virtual_network_id = var.virtual_network_id
}

```

Is there a way to _unbatch_ them, so as soon as **each** dns zone will get created the sleep will begin?

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [December 16, 2022, 7:31pm UTC](https://discuss.hashicorp.com/t/dependency-graph-bottleneck/48057/2 "2022-12-16T19:31:47Z")

</div>

Hi @pszypowicz,

Dependencies are between whole `resource` blocks rather than between individual instances, because the `for_each` expression itself also creates dependencies and so Terraform must build the dependency graph before resolving the individual instances.

There is no way to achieve a more precise dependency graph unless you write a separate `resource` block for each instance, instead of using `for_each`.

I think perhaps a better path here would be to fix the Azure provider so that its own `azurerm_private_dns_zone` resource type will wait until the object is actually ready before telling Terraform Core it is complete, thereby avoid the need for this hardcoded delay.

If there isn’t already an issue open for that then I’d suggest opening one in the provider’s own repository.
