0
0
Terraformcloud~20 mins

Resource dependencies (implicit) in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Dependency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2: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"
}
Aaws_vpc.main
Baws_subnet.subnet1
Caws_instance.web
DAll resources are created simultaneously
Attempts:
2 left
💡 Hint
Look at which resource IDs are referenced by others.
Architecture
intermediate
2: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"
}
Aaws_instance.app is created before the module resources
BThe module resources are created before aws_instance.app
CBoth are created simultaneously
DTerraform will throw an error due to circular dependency
Attempts:
2 left
💡 Hint
Consider how outputs create dependencies.
security
advanced
2: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?
ABoth are created simultaneously, which may cause the instance to have no security group
BThe instance is created before the security group, causing a security risk
CTerraform will fail to apply due to missing explicit dependency
DThe security group is created before the instance, ensuring the instance has the correct rules applied
Attempts:
2 left
💡 Hint
Think about resource references in arguments.
Configuration
advanced
2: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?
ATerraform fetches the AMI data before creating the instance
BTerraform creates the instance first, then fetches the AMI data
CTerraform fetches the AMI data and creates the instance simultaneously
DTerraform throws an error because data sources cannot be used as inputs
Attempts:
2 left
💡 Hint
Data sources provide information needed before resource creation.
Best Practice
expert
3: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?
AAvoid referencing resource attributes and rely on manual apply order
BRemove all references between resources to prevent dependencies
CUse explicit depends_on blocks to declare dependencies when implicit ones are unclear
DUse random resource names to force Terraform to recreate resources
Attempts:
2 left
💡 Hint
Explicit dependencies clarify creation order.