Bitzu

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

Single choice

Which expression refers to the id attribute of a resource declared as resource "aws_vpc" "main" {}?

  1. resource.aws_vpc.main.id
  2. data.aws_vpc.main.id
  3. aws_vpc.main.id
  4. 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.

Select all that apply

Which statements about references and dependencies are true?

  1. A reference to another resource's attribute creates an implicit dependency
  2. Resources are created in the order they appear in the file
  3. Terraform builds a dependency graph from references
  4. Resources with no dependency between them can be processed in parallel
  5. 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

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.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module