0
0
Terraformcloud~10 mins

Depends_on for explicit dependencies in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add an explicit dependency on the resource 'aws_vpc.main'.

Terraform
resource "aws_subnet" "example" {
  vpc_id = aws_vpc.main.id
  cidr_block = "10.0.1.0/24"
  [1] = [aws_vpc.main]
}
Drag options to blanks, or click blank then click option'
Aprovider
Bdepends_on
Clifecycle
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'provider' instead of 'depends_on'.
Forgetting to wrap the resource in a list.
2fill in blank
medium

Complete the code to explicitly depend on both 'aws_vpc.main' and 'aws_internet_gateway.gw'.

Terraform
resource "aws_route_table" "rt" {
  vpc_id = aws_vpc.main.id
  [1] = [aws_vpc.main, aws_internet_gateway.gw]
}
Drag options to blanks, or click blank then click option'
Acount
Bprovider
Cdepends_on
Dlifecycle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count' or 'provider' instead of 'depends_on'.
Not using a list for multiple dependencies.
3fill in blank
hard

Fix the error in the code by correctly specifying the explicit dependency on 'aws_security_group.sg'.

Terraform
resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  [1] = [aws_security_group.sg]
}
Drag options to blanks, or click blank then click option'
Adepends_on
Bdepends
Cdependency
DdependsOn
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase or incorrect spellings like 'dependsOn' or 'dependency'.
Omitting the list brackets around the resource.
4fill in blank
hard

Fill both blanks to explicitly depend on 'aws_lb.main' and 'aws_lb_target_group.main'.

Terraform
resource "aws_lb_listener" "front_end" {
  load_balancer_arn = aws_lb.main.arn
  port              = 80
  protocol          = "HTTP"
  [1] = [aws_lb.main, [2]]
}
Drag options to blanks, or click blank then click option'
Adepends_on
Baws_lb_target_group.main
Dprovider
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'provider' instead of 'depends_on'.
Not including both resources in the list.
5fill in blank
hard

Fill all three blanks to explicitly depend on 'aws_db_instance.main' and 'aws_security_group.db_sg'.

Terraform
resource "aws_db_parameter_group" "db_pg" {
  name        = "my-db-pg"
  family      = "mysql5.7"
  description = "Custom parameter group"
  [1] = [[2], [3]]
}
Drag options to blanks, or click blank then click option'
Adepends_on
Baws_db_instance.main
Caws_security_group.db_sg
Daws_subnet.db_subnet
Attempts:
3 left
💡 Hint
Common Mistakes
Not using a list for multiple dependencies.
Including resources not needed for this dependency.