0
0
Terraformcloud~20 mins

Depends_on for explicit dependencies in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Depends_on Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the purpose of depends_on in Terraform

What is the main purpose of using depends_on in a Terraform resource configuration?

ATo create a resource only if another resource exists in the cloud provider
BTo explicitly specify resource creation order when Terraform cannot infer it automatically
CTo define variables that are used inside resource blocks
DTo automatically delete dependent resources when a resource is destroyed
Attempts:
2 left
💡 Hint

Think about situations where Terraform might not know which resource to create first.

Configuration
intermediate
2:00remaining
Identifying the effect of depends_on in resource creation

Given the following Terraform snippet, what will be the order of resource creation?

resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
}

resource "aws_eip" "ip" {
  instance = aws_instance.web.id
  depends_on = [aws_instance.web]
}
ATerraform will throw an error due to circular dependency
BThe <code>aws_eip.ip</code> is created first, then <code>aws_instance.web</code>
CBoth resources are created simultaneously
DThe <code>aws_instance.web</code> is created first, then <code>aws_eip.ip</code>
Attempts:
2 left
💡 Hint

Look at the depends_on and the implicit reference inside aws_eip.

Architecture
advanced
2:30remaining
Using depends_on to manage complex resource dependencies

You have three resources: db, app, and monitoring. The app must be created after db, and monitoring must be created after both db and app. Which depends_on configuration correctly enforces this?

A<code>app depends_on = [db]</code> and <code>monitoring depends_on = [db, app]</code>
B<code>app depends_on = [monitoring]</code> and <code>monitoring depends_on = [db]</code>
C<code>db depends_on = [app]</code> and <code>monitoring depends_on = [app]</code>
D<code>monitoring depends_on = [db]</code> only
Attempts:
2 left
💡 Hint

Think about the order: db → app → monitoring.

security
advanced
2:30remaining
Impact of missing depends_on on security group rules

You have a security group resource and an instance resource. The instance uses the security group ID. If you forget to add depends_on for the instance on the security group, what could happen?

ATerraform might try to create the instance before the security group, causing a failure
BTerraform will automatically detect the dependency and create resources in correct order
CThe security group will be deleted before the instance is created
DTerraform will ignore the security group and create the instance without it
Attempts:
2 left
💡 Hint

Consider if Terraform can always detect dependencies from resource attributes.

service_behavior
expert
3:00remaining
Effect of depends_on on resource destruction order

Consider two Terraform resources: resource "aws_lb" "load_balancer" and resource "aws_lb_target_group" "target_group". The load balancer depends on the target group using depends_on. When destroying the infrastructure, what is the destruction order?

AThe load balancer is destroyed first, then the target group
BTerraform will fail to destroy due to dependency conflict
CThe target group is destroyed first, then the load balancer
DBoth are destroyed simultaneously
Attempts:
2 left
💡 Hint

Think about how depends_on affects destruction order compared to creation order.