Contents
Data sources allow Terraform to use information defined outside of Terraform, defined by another separate Terraform configuration, or modified by functions.
When Data Sources Are Read
Terraform attempts to query data sources during the planning phase, but depending on the configuration it may defer reading until the apply phase.
Terraform may defer reading when at least one of the arguments refers to a value that cannot be predicted during plan. This happens when:
- The
datablock directly depends on a Terraform-managed resource that is configured to change in the current plan. - The
datablock has custom conditions that directly or indirectly depend on a resource configured to change in the current plan. - Arguments in a
datablock refer to values that must be computed during the apply phase.
Data Block
data "<TYPE>" "<LABEL>" {
# ...
}You must set the following arguments for every data block:
TYPE— Specifies the data source type. Provider developers define the supported data sources. Terraform also includes theterraform_remote_statedata source, which lets you access state data from other workspaces.LABEL— Specifies a name for the data source. Use thedata.<label>.<attribute>syntax to reference the data.