Terraform: how to properly implement delay with for_each and time_sleep resource

A resource created by terraform after its creation comsumes CPU/RAM on cluster where it is created, so some kind of delay is needed before the next resource on the same cluster is created.

As an option to achieve this it was decided to use time_sleep terraform resource to implement some delay before resources creation.

It was also decided to use -parallelism=1 so that resources were created one by one.

Let’s say we have a module (as simple as it could be):

module test, main.tf

resource "time_sleep" "wait_3_seconds" {
  create_duration = "3s"

resource "null_resource" "topic_events" {
  triggers = {
    always_run = timestamp()
    topic = var.topic_name
  depends_on = [time_sleep.wait_3_seconds]

module test, variables.tf

variable topic_name {}

Main module invokes module test (see above):

module "test" {
  for_each= tomap(var.environments[var.dim_arr].clusters.events.topics)
  source = "./test"
  topic_name = "${var.dim_arr}.${each.value.topic}"

The logic is that input values are handled in the loop but because of the time_sleep resource in the test module some delay is introduced to this loop, that in turn should decrease a load to the server.

However terraform tries to create all time_sleep resources in the nested module and then inerates through the objects in the main module and creates them this way:

a) all time_sleep resources are created

b) all resources that depend on them (see a)) are created

Is there any way to change this logic, so that

-resouce that uses time sleep is created

-time_sleep resource causes delay to decrease a load on the cluster

-next object in the loop is handled

Any suggestions or ideas are appreciated.

Thank you.