Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What are implicit resource dependencies in Terraform?
Implicit resource dependencies happen automatically when one resource uses an attribute from another resource. Terraform understands the order to create resources without extra instructions.
Click to reveal answer
beginner
How does Terraform detect implicit dependencies?
Terraform detects implicit dependencies by looking at references in resource arguments. If a resource uses another resource's output, Terraform knows to create the second resource after the first.
Click to reveal answer
intermediate
Why are implicit dependencies preferred over explicit dependencies in Terraform?
Implicit dependencies keep configurations simple and clean. Terraform automatically manages the order, reducing errors and extra code compared to manually specifying dependencies.
Click to reveal answer
beginner
Give an example of an implicit dependency in Terraform.
If a virtual machine resource uses the ID of a network resource, Terraform knows to create the network first. For example, vm.network_id = network.id creates an implicit dependency.
Click to reveal answer
intermediate
Can implicit dependencies handle all resource creation order needs?
Most of the time, yes. But sometimes explicit dependencies are needed when resources don’t directly reference each other but still require order.
Click to reveal answer
What triggers an implicit dependency in Terraform?
ARunning terraform plan
BOne resource referencing another resource's attribute
CUsing depends_on explicitly
DUsing variables only
✗ Incorrect
Implicit dependencies happen when a resource uses another resource's attribute, so Terraform knows the order automatically.
Which is true about implicit dependencies?
ATerraform detects them automatically
BThey require manual declaration
CThey slow down resource creation
DThey are not recommended
✗ Incorrect
Terraform automatically detects implicit dependencies by analyzing resource references.
When might you need to use explicit dependencies instead of implicit?
AWhen resources do not reference each other but need order
BWhen using variables
CWhen creating only one resource
DWhen using modules
✗ Incorrect
Explicit dependencies are needed when resources don’t reference each other but must be created in a specific order.
What happens if Terraform does not detect a needed dependency?
ATerraform creates resources in random order
BTerraform fails to plan
CTerraform creates resources in parallel, possibly causing errors
DTerraform ignores the resource
✗ Incorrect
Without proper dependencies, Terraform may create resources in parallel, which can cause errors if order matters.
Which Terraform argument is used for explicit dependencies?
Arequire
Breference
Cdepends
Ddepends_on
✗ Incorrect
The depends_on argument is used to explicitly declare resource dependencies.
Explain how Terraform uses implicit dependencies to manage resource creation order.
Think about how one resource's input can come from another resource's output.
You got /3 concepts.
Describe a situation where implicit dependencies are not enough and explicit dependencies are needed.
Consider resources that must be created in sequence but don’t share attributes.
You got /3 concepts.
Practice
(1/5)
1. What does Terraform use to determine the order of resource creation when no explicit depends_on is set?
easy
A. The alphabetical order of resource names
B. The order resources are written in the file
C. References between resources inside the configuration
A. aws_vpc.main -> aws_subnet.subnet1 -> aws_instance.web
B. aws_instance.web -> aws_subnet.subnet1 -> aws_vpc.main
C. aws_subnet.subnet1 -> aws_vpc.main -> aws_instance.web
D. aws_vpc.main -> aws_instance.web -> aws_subnet.subnet1
Solution
Step 1: Identify dependencies from references
aws_subnet.subnet1 depends on aws_vpc.main via vpc_id. aws_instance.web depends on aws_subnet.subnet1 via subnet_id.
Step 2: Determine creation order
Terraform creates resources in order of dependencies: first aws_vpc.main, then aws_subnet.subnet1, then aws_instance.web.
Final Answer:
aws_vpc.main -> aws_subnet.subnet1 -> aws_instance.web -> Option A
Quick Check:
Dependency chain order = B [OK]
Hint: Follow references to find creation order [OK]
Common Mistakes:
Ignoring dependency direction
Assuming alphabetical or file order
Mixing up resource references
4. You have two resources: aws_security_group.sg and aws_instance.web. The instance should be created after the security group. The code is:
resource "aws_security_group" "sg" {
name = "web-sg"
}
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
}
Why might Terraform create the instance before the security group, and how to fix it?
medium
A. Because no reference exists; add vpc_security_group_ids = [aws_security_group.sg.id] to instance
B. Because depends_on is missing; add depends_on = [aws_security_group.sg] to instance
C. Because resource names are unordered; rename aws_security_group.sg to sg1
D. Because Terraform always creates instances first; no fix possible
Solution
Step 1: Identify missing implicit dependency
The instance resource does not reference the security group, so Terraform sees no dependency and may create in any order.
Step 2: Fix by adding reference
Adding vpc_security_group_ids = [aws_security_group.sg.id] creates an implicit dependency, ensuring the security group is created first.
Final Answer:
Add vpc_security_group_ids referencing security group to instance -> Option A
Quick Check:
Reference creates implicit dependency [OK]
Hint: Add resource attribute reference to create implicit dependency [OK]
Common Mistakes:
Relying only on depends_on when reference is better
Changing resource names expecting order change
Assuming Terraform creates instances first always
5. You have a Terraform configuration with three resources: aws_lb.lb, aws_lb_target_group.tg, and aws_lb_listener.listener. The listener must be created after the load balancer and target group. The target group references the load balancer's ARN. The listener references the target group's ARN. However, you want to ensure the listener is created only after both are fully ready. Which is the best way to enforce this implicit dependency correctly?
hard
A. Use explicit depends_on everywhere and avoid references
B. Reference aws_lb.lb.arn in aws_lb_target_group.tg and aws_lb_target_group.tg.arn in aws_lb_listener.listener without using depends_on
C. Create the listener first, then the target group and load balancer
D. Add depends_on = [aws_lb.lb, aws_lb_target_group.tg] in aws_lb_listener.listener and no references
Solution
Step 1: Understand implicit dependency chaining
Referencing aws_lb.lb.arn in the target group creates an implicit dependency on the load balancer. Referencing aws_lb_target_group.tg.arn in the listener creates an implicit dependency on the target group.
Step 2: Avoid unnecessary explicit depends_on
Using references allows Terraform to build the dependency graph automatically and safely without manual depends_on, which should be reserved for special cases.
Final Answer:
Use references to create implicit dependencies without depends_on -> Option B
Quick Check:
Implicit references chain dependencies best [OK]
Hint: Chain resource references to build implicit dependencies [OK]
Common Mistakes:
Overusing depends_on instead of references
Creating resources in wrong order manually
Avoiding references and relying only on depends_on