# How to add timeout between resource creation in terraform?

**URL:** <https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686>\
**Category:** Terraform\
**Created:** [July 2, 2025, 1:09pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686 "2025-07-02T13:09:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![voipp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/voipp/32/46015_2.png) [@voipp](https://discuss.hashicorp.com/u/voipp)\
**Post date:** [July 2, 2025, 1:09pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/1 "2025-07-02T13:09:56Z")

</div>

I create several **openstack\_compute\_instance\_v2** resources,  
how to add some timeout between creation of the resource and the next one?  
So, after terraform aply, my resources will be created and some timeout will by waiting between creation of them

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [July 2, 2025, 5:24pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/2 "2025-07-02T17:24:31Z")

</div>

I don’t see any timeout options for the `openstack_compute_instance_v2` in their documentation, but I don’t think I understand what it is you’re asking about with timeouts between resources. Can you give an example of what you’re trying to do?

---

<div class="post-metadata">

**Author:** ![voipp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/voipp/32/46015_2.png) [@voipp](https://discuss.hashicorp.com/u/voipp)\
**Post date:** [July 2, 2025, 5:32pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/3 "2025-07-02T17:32:40Z")

</div>

I need to add some timeout bewteen resource instance creation.  
My resource looks like

```auto
resource "openstack_compute_instance_v2" "master" {
  for_each = var.vm_instances
  name = each.key
....
}

```

Then create isnatnces like:

```auto
module "create_vms" {
  source = "../modules/compute_vs"

  vm_instances = {
isntance1 = {...}
instance2={...}
...

```

I finally found a way to do it. Need to insert in resource:

```auto
  provisioner "local-exec" {
    command = "sleep 120"
  }

```

Now, it seems, terraform waits 2 mins before creating the next isntance

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [July 2, 2025, 5:39pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/4 "2025-07-02T17:39:46Z")

</div>

It sounds like you want to insert a delay between each instance, but when you use `for_each` there is no ordering of the instances, and they can even be created concurrently.

It’s generally not a good idea to rely on arbitrary delays to ensure resource deployment is correct, but if you need to workaround a problem there is also the [`time_sleep`](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) resource which can create a delay between dependencies with a little more control than the provisioner. You would have to write out individual resource blocks however to ensure there is a specified dependency order between the resources, but that would be the case using the `local-exec` provisioner as well.

---

<div class="post-metadata">

**Author:** ![voipp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/voipp/32/46015_2.png) [@voipp](https://discuss.hashicorp.com/u/voipp)\
**Post date:** [July 2, 2025, 5:44pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/5 "2025-07-02T17:44:24Z")

</div>

well, i create compute instance resource with our company’s custom image. And this image has flaws causing machine creation failure if i create concurrently too many instances at once.  
So i need pause between them)

---

<div class="post-metadata">

**Author:** ![voipp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/voipp/32/46015_2.png) [@voipp](https://discuss.hashicorp.com/u/voipp)\
**Post date:** [July 2, 2025, 5:47pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/6 "2025-07-02T17:47:37Z")

</div>

Should i rewrite my resource definition to smth like this?

```auto
resource "time_sleep" "wait_2_minutes" {
  create_duration = "2m"
}

resource "openstack_compute_instance_v2" "master" {
  for_each = var.vm_instances
  name = each.key
....
depends_on = [time_sleep.wait_2_minutes]
}

```

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [July 2, 2025, 5:56pm UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/7 "2025-07-02T17:56:21Z")

</div>

Using a provisioner like you did might delay some instances from being created; for example you might get a batch of 10, then a 2 min delay, then another batch of 10, etc. If concurrency itself is the problem, then you can use the `-parallelism` flag to reduce the concurrency in the CLI, but that unfortunately affects everything for now.

Your latest example doesn’t delay anything other than the start of evaluating the entire set of `openstack_compute_instance_v2` instances. The only way to declare a specific delay between every instance would be to write each `openstack_compute_instance_v2` instance in it’s own block with a separate `time_sleep` between them.

The optimal solution of course would be to fix this at the image level to prevent the failure in the first place. Terraform is going to expect that once the provider reports the apply action is complete, it can move on to the next waiting resource, and adding a delay is only guessing at what else might be happening behind the scenes.

---

<div class="post-metadata">

**Author:** ![voipp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/voipp/32/46015_2.png) [@voipp](https://discuss.hashicorp.com/u/voipp)\
**Post date:** [July 3, 2025, 7:17am UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/8 "2025-07-03T07:17:44Z")

</div>

Hello! Thanks for the assitance . I also added -parallelism=1 and now it works as I dreamed. Declaring explicitly resource block for each instance would be tedious as i have 38 instances to create

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/hashicorp/original/1X/79bf76adfd92a75631996933098f9ce29d37abf3.svg) [@system](https://discuss.hashicorp.com/u/system)\
**Post date:** [December 30, 2025, 7:17am UTC](https://discuss.hashicorp.com/t/how-to-add-timeout-between-resource-creation-in-terraform/75686/9 "2025-12-30T07:17:49Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
