Terraform depends_on and count elements

Hi all,
can I put on terraform some depeneds_on with some count into elements?

This is an example:

  1. create resource1 with count_index = 4
  2. create resource2 with count_index= 4
  3. create resource3 with depends_on = [ resource1[index], resource2[index]]


Hi @cello86,

Terraform will allow you to declare depends_on = [ aws_instance.example[0] ], but Terraform treats that exactly the same as depends_on = [ aws_instance.example ], because dependencies are between the entire resource blocks rather than their individual instances.

Terraform does not yet know how many instances of a resource are declared when it is building the dependency graph. The count argument can have its own dependencies, so Terraform must build the dependency graph before evaluating that expression.

Hi @apparentlymart
thanks for the response.

Ideally, if the 4 instances of resource1 and resource2 will not be available, the creation of the first resource3 will not be initiated. I’m wrong