Challenge - 5 Problems
Terraform Dependency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Implicit resource dependency in Terraform
Given the following Terraform configuration, which resource will Terraform create first during apply?
Terraform
resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" } resource "aws_subnet" "subnet1" { vpc_id = aws_vpc.main.id cidr_block = "10.0.1.0/24" } resource "aws_instance" "web" { subnet_id = aws_subnet.subnet1.id ami = "ami-123456" instance_type = "t2.micro" }
Attempts:
2 left
💡 Hint
Look at which resource IDs are referenced by others.
✗ Incorrect
Terraform automatically creates resources in the order of their dependencies. Since aws_subnet.subnet1 depends on aws_vpc.main (via vpc_id), and aws_instance.web depends on aws_subnet.subnet1 (via subnet_id), aws_vpc.main is created first.
❓ Architecture
intermediate2:00remaining
Understanding implicit dependencies in Terraform modules
If a Terraform module outputs a resource ID that another resource uses as input, what does this imply about the creation order?
Terraform
module "network" { source = "./network" } resource "aws_instance" "app" { subnet_id = module.network.subnet_id ami = "ami-abc123" instance_type = "t3.micro" }
Attempts:
2 left
💡 Hint
Consider how outputs create dependencies.
✗ Incorrect
Since aws_instance.app uses an output from the module as input, Terraform implicitly creates the module resources first to provide the required value.
❓ security
advanced2:30remaining
Implicit dependency impact on security group rules
Consider these Terraform resources:
resource "aws_security_group" "sg" {
name = "allow_http"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "web" {
ami = "ami-xyz"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.sg.id]
}
What is the effect of the implicit dependency on the security of the deployment?
Attempts:
2 left
💡 Hint
Think about resource references in arguments.
✗ Incorrect
Because aws_instance.web references aws_security_group.sg.id, Terraform creates the security group first, ensuring the instance is launched with the correct security settings.
❓ Configuration
advanced2:00remaining
Terraform implicit dependency with data sources
Given this Terraform snippet:
data "aws_ami" "latest" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
}
resource "aws_instance" "example" {
ami = data.aws_ami.latest.id
instance_type = "t2.micro"
}
What does Terraform do regarding the order of resource creation?
Attempts:
2 left
💡 Hint
Data sources provide information needed before resource creation.
✗ Incorrect
Terraform evaluates data sources before creating dependent resources, so it fetches the AMI ID before launching the instance.
✅ Best Practice
expert3:00remaining
Avoiding implicit dependency pitfalls in complex Terraform configurations
In a complex Terraform setup, you have multiple resources referencing each other indirectly. Which practice helps ensure predictable resource creation order and avoids hidden implicit dependency issues?
Attempts:
2 left
💡 Hint
Explicit dependencies clarify creation order.
✗ Incorrect
Explicit depends_on blocks help Terraform understand resource order when implicit references are not obvious, preventing race conditions and errors.