Skill 4.2.1

Resource and data source references

Key Concepts

A reference such as aws_subnet.app.id reads the id attribute of the aws_subnet.app resource. If the resource uses count or for_each, the reference must select an instance: aws_subnet.app[0].id or aws_subnet.app["a"].id. Nested attributes are reached with dots and indexes, such as aws_instance.web.root_block_device[0].volume_size.

Every reference creates an implicit dependency: Terraform creates or updates the referenced object first. Attributes computed by the provider during creation appear as (known after apply) in a plan until the object exists.