Skill 4.6.2

Explicit dependencies with depends_on

Key Concepts

Sometimes a resource relies on another's behaviour without using any of its values. For example, an application instance might need an IAM role policy to be attached before it starts, although it only references the role. depends_on = [aws_iam_role_policy.app] tells Terraform to finish that resource first. The value is a list of references to whole resources or modules, not attributes.

depends_on works on resources, data sources, modules and outputs. Use it as a last resort: it makes Terraform more conservative, for example by deferring a data source's read to apply time when its dependency has changes, which can cause more values to be unknown during planning.