0
0
Terraformcloud~5 mins

Depends_on for explicit dependencies in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of depends_on in Terraform?

depends_on explicitly tells Terraform that one resource must be created or updated before another. It controls the order of operations to avoid errors.

Click to reveal answer
beginner
How does Terraform normally determine resource creation order without depends_on?

Terraform uses implicit dependencies by analyzing references between resources, like when one resource uses an output or attribute of another.

Click to reveal answer
intermediate
When should you use depends_on in your Terraform configuration?

Use depends_on when Terraform cannot detect a dependency automatically but you know one resource must be created before another, such as with external resources or side effects.

Click to reveal answer
intermediate
What happens if you omit depends_on when an explicit dependency is needed?

Terraform may try to create or update resources in the wrong order, causing errors or failures during deployment.

Click to reveal answer
beginner
Example: How to use depends_on to make resource B wait for resource A?
resource "aws_instance" "A" {
  # config
}

resource "aws_instance" "B" {
  # config
  depends_on = [aws_instance.A]
}
Click to reveal answer
What does depends_on do in Terraform?
AChanges resource configuration
BSpecifies explicit resource creation order
CDeletes resources automatically
DCreates new resource types
How does Terraform find dependencies without depends_on?
ABy user input only
BBy random order
CBy analyzing resource references
DIt does not find dependencies
When is depends_on necessary?
AWhen Terraform cannot detect a dependency automatically
BAlways, for every resource
COnly for deleting resources
DNever, it is deprecated
What is a risk of missing a needed depends_on?
ATerraform will crash immediately
BTerraform will ignore the resource
CResources will be duplicated
DResources may be created in wrong order causing errors
Which syntax correctly uses depends_on?
Adepends_on = [aws_instance.A]
Bdepends_on = aws_instance.A
Cdepends_on: aws_instance.A
Ddepends_on => aws_instance.A
Explain in your own words why and how you would use depends_on in Terraform.
Think about cases where Terraform might not know which resource to create first.
You got /4 concepts.
    Describe what could happen if you forget to add depends_on when it is needed.
    Consider the impact on your infrastructure deployment process.
    You got /4 concepts.