Can a List of Resources be used in the depends_on Property

Can a resource’s depends_on be used against all elements in a "resource list". For example, in the resource below, the source_ids’ property is enumerated, however, I get an error when I attempt to concat() those elements in the depends_on with other elements.

The code below is valid and deploys, however, I don’t know if that is a valid construct for depends_on. Does it wait for all elements in the “resource collection”? If not, is there a better alternative?

In the example below, resource aws_dms_replication_instance.dms_instances{} contains more than one instance.

resource "aws_dms_event_subscription" "event_subscription_repl_instance_bronze" {

    count               = length(lookup(var.dms_notification_emails, terraform.workspace))    
     ...   
    source_ids           = [for ri in aws_dms_replication_instance.dms_instances : ri.replication_instance_id]
   
    depends_on = [
         aws_dms_replication_instance.dms_instances         
        ]    
}

>Solution :

In your case you do not need depends_on as you have existing implicit relation already setup through:

source_ids           = [for ri in aws_dms_replication_instance.dms_instances : ri.replication_instance_id]

So depends_on is redundant. But yes, it will wait for all instances of aws_dms_replication_instance.dms_instances to be deployed if you did not have source_ids.

Leave a Reply