Terraform Associate 004 ยท Configuration building blocks
Attribute references and the dependency graph
TYPE.NAME.ATTRIBUTE syntax, data.TYPE.NAME, references building the dependency graph, known after apply (4b).
Key points
- Refer to a managed resource as TYPE.NAME.ATTRIBUTE (aws_vpc.main.id) and to a data source as data.TYPE.NAME.ATTRIBUTE.
- Each reference creates an implicit dependency, so Terraform builds its graph from them and creates the referenced object first.
- Values the provider only assigns at creation are shown as "known after apply" in a plan.
Practice questions
Which expression refers to the id attribute of a resource declared as resource "aws_vpc" "main" {}?
- resource.aws_vpc.main.id
- data.aws_vpc.main.id
- aws_vpc.main.id
- main.aws_vpc.id
Show answer
Answer: C. aws_vpc.main.id
A managed resource is referenced as TYPE.NAME.ATTRIBUTE with no resource. prefix. The data. prefix is only for data sources.
Which statements about references and dependencies are true?
- A reference to another resource's attribute creates an implicit dependency
- Resources are created in the order they appear in the file
- Terraform builds a dependency graph from references
- Resources with no dependency between them can be processed in parallel
- A data source is referenced as TYPE.NAME.ATTRIBUTE
Show answer
Answer: A. A reference to another resource's attribute creates an implicit dependency, C. Terraform builds a dependency graph from references, D. Resources with no dependency between them can be processed in parallel
References create implicit dependencies and the graph determines ordering, not file order. Independent resources may be handled in parallel. Reference syntax for data sources needs the data. prefix.
True or false: moving a resource block to the top of a file makes Terraform create it first.
Show answer
Answer: False
False. Block order in files is irrelevant; the dependency graph built from references decides the order.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
