Depends_on
In this lesson, we'll discuss the depends_on attribute in detail.
We'll cover the following
Depends_on
We have seen thus far that, where possible, you should tell Terraform about dependencies by referring to one resource in the one that depends on it. The depends_on
attribute offers a way to specify a dependency by hand. This can be useful if there is a
hidden dependency that Terraform would otherwise not know about.
Example
For example, if you are creating an S3 bucket and an IAM policy that allows writing to
the S3 bucket, then you should get the ARN of the S3 bucket from the property aws_s3_bucket.arn
of the resource.
In that case, Terraform will internally build a graph that the S3 bucket needs
to be created before the IAM role. There are some circumstances where there is a dependency that you cannot model like this, though.
In those cases, you can explicitly tell Terraform that a resource depends
on another resource by using the depends_on
attribute and then using the full path to the resource.
Get hands-on with 1400+ tech skills courses.