data source
A data block that asks a provider to look up an existing object and return its details, without Terraform creating or owning it.
In more detail
Use one when you need a value from something another team or configuration manages; use a resource only when this configuration should create, change or delete it. Data sources are read during refresh, or during apply if their inputs are unknown, and are addressed as data.<type>.<name>. A failed lookup is a real error, because it means an assumption is wrong.
Examples
data "local_file" "source" {
filename = "source.txt"
}content = data.local_file.source.contentRelated terms
- Terraform resource — A resource block, which asks Terraform to create and manage one piece of infrastructure such as a network, file or database.
- known after apply — What a plan shows for a value that cannot exist until apply, such as an identifier or checksum the provider will generate.
- remote state — Reading another configuration's output values from its state, using the terraform_remote_state data source.
Related guides
Taught in
- Predicting Changes, Then Applying Them — Infrastructure as Code with Terraform
- Functions And Expressions In HCL — Infrastructure as Code with Terraform
- Querying Existing Infrastructure With Data Sources — Infrastructure as Code with Terraform
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Reading A Plan, Saving It, Applying It — HashiCorp Terraform Associate (004) Exam Prep
- Validate, Format, Destroy, And The Flags That Bend A Plan — HashiCorp Terraform Associate (004) Exam Prep
- Resources, Data Sources And The References Between Them — HashiCorp Terraform Associate (004) Exam Prep
- Input Variables, Outputs, And Which Value Wins — HashiCorp Terraform Associate (004) Exam Prep
- Dependencies, depends_on And Lifecycle Rules — HashiCorp Terraform Associate (004) Exam Prep
- Custom Conditions: Validation, Pre And Postconditions, Checks — HashiCorp Terraform Associate (004) Exam Prep
- Sensitive Data, Ephemeral Values And Secrets From Vault — HashiCorp Terraform Associate (004) Exam Prep