Lesson 1 of 4 ยท Resource Relationships & Dependencies
References and attributes
A resource reference usually has three pieces: type, local name, and attribute. In aws_vpc.main.id, aws_vpc is the type, main is the local name, and id is the value Terraform reads from that resource.
Example
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
}Step by step
- Find the resource block first.
- Match its type and local name exactly.
- Use an attribute that the resource exposes.
- Let Terraform infer the order from the reference.
Common mistakes to avoid
- Using the cloud display name instead of the Terraform local name.
- Guessing an attribute without checking provider documentation.