Back to course

Resource Dependencies: Implicit vs Explicit

Infrastructure as Code (Terraform & OpenTofu Mastery)

Order Matters

You can't create a server in a network that doesn't exist yet. OpenTofu usually handles this automatically.

1. Implicit Dependency

If you use aws_vpc.main.id inside an aws_subnet block, OpenTofu knows to create the VPC first.

2. Explicit Dependency

Sometimes OpenTofu doesn't see the link. Use depends_on: hcl resource "aws_instance" "web" {

...

depends_on = [aws_s3_bucket.example] }

This forces the server to wait until the S3 bucket is created.