Skill 4.1.2
Data blocks
Key Concepts
A data source is declared with data "TYPE" "NAME" and referenced as data.TYPE.NAME.ATTRIBUTE. Its arguments are query constraints, such as filters or a name, and its attributes are the results. Examples include aws_ami to find an image ID, aws_caller_identity to read the current account ID, and terraform_remote_state to read another configuration's outputs.
Terraform never creates, changes or destroys the object behind a data source. It reads data sources during planning, unless an argument depends on a value that is unknown until apply, in which case the read is deferred to the apply step. Use a data source when an object is managed elsewhere, by another team or another configuration, and a resource when this configuration owns its lifecycle.